Rails 3 - how can I customize text-label in label helper?

佐手、 提交于 2019-12-10 03:22:38

问题


This is probably a bit low question, but is there any elegant way, how to change the label-text in label helper?

= f.label :name

generate

<input id="car_name" name="car[name]" size="30" type="text">

If I would like to have the text in label, say, Your Car instead of Name, how to do that?

One way is to write the label tag directly as HTML, but this is a bit dirty way...


回答1:


Just add a second string argument to f.label, like this:

label_tag 'name', 'Your name'
# => <label for="name">Your Name</label>

See here



来源:https://stackoverflow.com/questions/10473565/rails-3-how-can-i-customize-text-label-in-label-helper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!