ruby-on-railsrubyruby-on-rails-3.2form-for

Rails: Custom text for rails form_for label


I want to display a label in form_for:

<div class="field">
  <%= f.label :name %><br />
  <%= f.text_field :name %>
</div>

This generates the label "Name", but I want it to be "Your Name". How can I change it?


Solution

  • The second parameter to label helper will allow you to set custom text.

    <%= f.label :name, 'Your Name' %>
    

    Use Ruby on Rails Documentation to look up helper methods.