开发者

Parameters of partial renders, ROR3

开发者 https://www.devze.com 2023-02-20 05:31 出处:网络
I have this hack to make the partial render work, because the partial render only works with the instance variable @product. I\'m pretty su开发者_JS百科re it\'s not the best way to work this out, can

I have this hack to make the partial render work, because the partial render only works with the instance variable @product. I'm pretty su开发者_JS百科re it's not the best way to work this out, can someone please point a better way?

 <% products.each do |product| %>
    <% @product=product %>
    <%= render 'cart_form', :product => @product %>


You might want to render a collection here without using the .each loop. Take a look at the RailsGuides and try something like this:

<%= render :partial => "cart_form", :collection => @products %>

(and set @products in your controller)

0

精彩评论

暂无评论...
验证码 换一张
取 消