6

我的观点是这样的:

render  :partial  => 'shared/_address', :locals   => {:address => order.bill_address}

部分看起来像这样:

  <b><%= address.name %></b><br/>
  <%= raw address.address_lines('<br/>') %><br/>
  <%= address.city_state_zip %><br/>

页面上有多个部分呈现的实例。我如何修改我的渲染:部分行,而不是让它显示 address.name,以便我传递一个自定义字符串,例如“Future Shipping Address”,而不必使用 address.name?

所以代码如下所示:

  <b>STRING GOES HERE</b><br/>
  <%= raw address.address_lines('<br/>') %><br/>
  <%= address.city_state_zip %><br/>
4

2 回答 2

4

尝试:

render :partial => 'shared/address', :locals => {:my_string=>"my string", :address => order.bill_address}

部分地

<b><%= my_string %></b><br/>
<%= raw address.address_lines('<br/>') %><br/>
<%= address.city_state_zip %><br/>
于 2013-02-26T05:51:57.483 回答
2

view:

render 'shared/_address', address: order.bill_address, custom_string: 'foobar'

partial:

<b><%= custom_string %></b>
<%= raw address.address_lines('<br/>') ....
于 2013-02-26T05:07:52.943 回答