我想在我的部分中使用两个集合@ad_item和@user。这是我的索引erb ...
<% if @ad_items.any? && @user.any? %>
<%= render partial: 'yourads/ad_item', collection: {@ad_items,@user} %>
<% end %>
这是我的控制器......
def index
@ad_items = Yourad.all
@user = User.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @yourads }
end
端
这是我的_ad_item.erb.html部分
<span class="date"><%= ad_item.created_at.to_date() %></span>
<span class="location"><%= ad_item.title %></span>
<div style="float:left"><%= ad_pic @user,ad_item %></div>
<div class="description"><%= ad_item.description %></div>
我的助手功能是..
def ad_pic(user,ad)
cl_image_tag("Ad#{user.id}#{ad.id}.jpg", :version => rand(1000000000), :alt => "Ad pic",:width => 70, :height => 70, :crop => :fill)
end
它在..
中出现语法错误<%= render partial: 'yourads/ad_item', collection: {@ad_items,@user} %>
答案 0 :(得分:0)
<%= render partial: 'yourads/ad_item', :locals => {:ad_items=>@ad_items,:user => @user }%>
您可以在yourads / ad_item partial中以 ad_items 和 @user 作为用户访问 @ad_items < / p>
答案 1 :(得分:0)
<%= render partial: 'yourads/ad_item', collection: @ad_items ,
locals: {users: @users} %>
并在视野中
<% for user in users %>
<span class="date"><%= ad_item.created_at.to_date() %></span>
<span class="location"><%= ad_item.title %></span>
<div style="float:left"><%= ad_pic user,ad_item %></div>
<div class="description"><%= ad_item.description %></div>
<% end %>