Rails:使用动态值自定义表单的标签(Rails: Customize a form's label with a dynamic value)

我的应用程序中有一个标签,如下所示。

<div class = "form-group"> <%= form.label :shipping_destination,:class =>'col-sm-2'%> </div>

我想要设置一个来自Spree的动态值,而不是显示“送货目的地”

<%=@order.shipping_address.country.name %>

如何将此值作为标签传递给标签?

I have a label in my app like below.

<div class = "form-group"> <%= form.label :shipping_destination,:class =>'col-sm-2'%> </div>

Instead of showing "Shipping Destination", I want to set a dynamic value coming from Spree, which is

<%=@order.shipping_address.country.name %>

How do I pass this as a value to the label?

最满意答案

<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,@order.shipping_address.country.name,:class =>'col-sm-2'%> </div>

EDIT Just pass the string as second argument to the label form helper to customize the label name

<%= form.label :shipping_destination,"My Custom Label",:class =>'col-sm-2'%>Rails:使用动态值自定义表单的标签(Rails: Customize a form's label with a dynamic value)

我的应用程序中有一个标签,如下所示。

<div class = "form-group"> <%= form.label :shipping_destination,:class =>'col-sm-2'%> </div>

我想要设置一个来自Spree的动态值,而不是显示“送货目的地”

<%=@order.shipping_address.country.name %>

如何将此值作为标签传递给标签?

I have a label in my app like below.

<div class = "form-group"> <%= form.label :shipping_destination,:class =>'col-sm-2'%> </div>

Instead of showing "Shipping Destination", I want to set a dynamic value coming from Spree, which is

<%=@order.shipping_address.country.name %>

How do I pass this as a value to the label?

最满意答案

<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,@order.shipping_address.country.name,:class =>'col-sm-2'%> </div>

EDIT Just pass the string as second argument to the label form helper to customize the label name

<%= form.label :shipping_destination,"My Custom Label",:class =>'col-sm-2'%>