Rails 3-如何在标签助手中自定义文本标签? [英] Rails 3 - how can I customize text-label in label helper?

查看:66
本文介绍了Rails 3-如何在标签助手中自定义文本标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个较低的问题,但是有什么优雅的方法,如何在 label 帮助器中更改标签文本?

= f.label :name

生成

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

如果我想在标签中使用文字,例如 Your Car (您的车)而不是 Name (姓名),,该怎么做?

一种方法是直接将标签标签编写为HTML,但这有点脏...

解决方案

只需向f.label添加第二个字符串参数,就像这样:

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

请参见此处

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...

解决方案

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

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

See here

这篇关于Rails 3-如何在标签助手中自定义文本标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆