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

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

Add Comment


  • 3 Answer(s)

    Using rails >= 3.0, you can simply use the placeholder option.

    f.text_field :attr, placeholder: "placeholder text"
    

    Answered on January 10, 2019.
    Add Comment

    Using HAML on Rails 4:

    =f.text_field :first_name, class: 'form-control', autofocus: true, placeholder: 'First Name'
    

    Answered on January 10, 2019.
    Add Comment

    Rails(4.2) Internationalization (I18n): Placeholder attribute is true

    f.text_field :attr, placeholder: true
    

    Local file (ie. en.yml):

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

    Answered on January 10, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.