Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass string into Rails partial?

I have a view that is like this:

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

With a partial that looks like this:

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

There are multiple instances of the partial rendered on a page. Instead of having it display address.name, how can I modify my render :partial line so that I am passing on a custom string e.g. "Future Shipping Address" instead of having to use address.name?

So the code would look like below:

  <b>STRING GOES HERE</b><br/>
  <%= raw address.address_lines('<br/>') %><br/>
  <%= address.city_state_zip %><br/>
like image 620
mztwo Avatar asked Feb 26 '13 04:02

mztwo


1 Answers

Try:

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

in partial

<b><%= my_string %></b><br/>
<%= raw address.address_lines('<br/>') %><br/>
<%= address.city_state_zip %><br/>
like image 194
shweta Avatar answered Nov 03 '22 22:11

shweta