简体   繁体   English

我如何让Rails在表单中使用自定义字符串标签

[英]How do I get Rails to use a custom string label for form

I have a User model that has a Name attribute, but I plan to use it more as a username. 我有一个具有Name属性的User模型,但我打算将它更多地用作用户名。 In the standard for label usage it has :name for the label, so Name shows up when the user sees the form. 在标签使用标准中,标签具有:name,因此当用户看到表单时会显示Name。 How can I force it to use a customer string "Username" label for this attribute in the form so that the :name attribute in the model actually contains the user's username. 我该如何强制它在表单中为此属性使用客户字符串“ Username”标签,以便模型中的:name属性实际上包含用户的用户名。 Thanks, Edward 谢谢,爱德华

您只需要在:name字段之后添加它,就像这样

<%= form.label :name, "Username" %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM