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
Like the guides said,
specify the :as
option in the call to the partial
For Rails 4.x, if you pass the collection directly to render (which you must do if you want to use automatic partial selection for a heterogeneous collection), the next parameter is interpreted as a hash of locals.
Try the following:
= render @enquiry.available_car_types, :path => customers_enquiry_path
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With