views:

29

answers:

2

Everything works okay when I try to render a partial like this:

= render :partial => "/shared/enquiry/car_type", :collection => @enquiry.available_car_types

However, if I also want to pass a variable (in this case 'path', because I'm sharing this partial across two forms), the path is not available to me:

= render :partial => "/shared/enquiry/car_type", :collection => @enquiry.available_car_types, :locals => {:path => customers_enquiry_path}

I've tried moving things around, but nothing appears to work, leading me to believe one cannot use locals with collections. Any help would be appreciated.

Gav

+1  A: 

No you can't use them together. Ref this

I think you have to do something like following

  <% for ad in @enquiry.available_car_types %>
    <%= render :partial => "/shared/enquiry/car_type", :locals =>{ :ad => ad, :path =>customers_enquiry_path } %>
  <% end %>
Salil
A: 

What version are you using? Using my 2.3.5 I'm able to do just that:

render :partial => "/site_articles/article", :collection => @site_articles, :locals => { :footer => true }

, which you can find explained in other places, such as 3.4.6 of this.

par