开发者

Changing the text on a label in form_for

I have this code in my view (for the "debate" class):

<%= form_for(@debate) do |f| %>
...
    <%= f.label :proposition, :body %>
...
<% end %>

and this in my en.yml:

helpers:
  label:
    debate:
      body: "Testing label body"

that I copied from this page: http://apidock.com/rails/ActionView/Helpers/FormHelper/label

expecting that it would resul开发者_开发问答t in <label for="debate_body">Testing label body</label> being output to the page, but instead I get <label for="debate_proposition">body</label>

I tried some other, things, like swapping "debate" with "proposition" in en.yml with no luck. What am I doing wrong?


The example in the API does not use form_for, so you need to pass in the object to label. Since you do use form_for, that argument can be skipped. So the correct way would be:

<%= form_for(@debate) do |f| %>
...
    <%= f.label :proposition %>
...
<% end %>

And:

helpers:
  label:
    debate:
      proposition: "Testing label body"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜