Rails: 使用动态值自定义表单标签
Rails: Customize a form's label with a dynamic value
我的应用程序中有一个标签,如下所示。
<div class = "form-group">
<%= form.label :shipping_destination,:class =>'col-sm-2'%>
</div>
我不想显示 "Shipping Destination",而是想设置一个来自 Spree 的动态值,即
<%=@order.shipping_address.country.name %>
如何将其作为值传递给标签?
<div class = "form-group">
<%= form.label :shipping_destination,@order.shipping_address.country.name,:class =>'col-sm-2'%>
</div>
编辑
只需将字符串作为第二个参数传递给标签表单助手即可自定义标签名称
<%= form.label :shipping_destination,"My Custom Label",:class =>'col-sm-2'%>
我的应用程序中有一个标签,如下所示。
<div class = "form-group">
<%= form.label :shipping_destination,:class =>'col-sm-2'%>
</div>
我不想显示 "Shipping Destination",而是想设置一个来自 Spree 的动态值,即
<%=@order.shipping_address.country.name %>
如何将其作为值传递给标签?
<div class = "form-group">
<%= form.label :shipping_destination,@order.shipping_address.country.name,:class =>'col-sm-2'%>
</div>
编辑
只需将字符串作为第二个参数传递给标签表单助手即可自定义标签名称
<%= form.label :shipping_destination,"My Custom Label",:class =>'col-sm-2'%>