Rails: Custom text for rails form_for label

Paul S. picture Paul S. · Oct 22, 2012 · Viewed 70.6k times · Source

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?

Answer

gylaz picture gylaz · Oct 22, 2012

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.