Ruby on Rails: How do I add placeholder text to a f.text_field?

前端 未结 6 1277
囚心锁ツ
囚心锁ツ 2021-01-29 21:57

How can I add placeholder text to my f.text_field fields so that the text comes pre-written by default, and when a user click inside the fields, the te

6条回答
  •  后悔当初
    2021-01-29 22:14

    For those using Rails(4.2) Internationalization (I18n):

    Set the placeholder attribute to true:

    f.text_field :attr, placeholder: true
    

    and in your local file (ie. en.yml):

    en:
      helpers:
        placeholder:
          model_name:
            attr: "some placeholder text"
    

提交回复
热议问题