这是如此简单,它不应该是一个问题,但我不明白什么怎么回事。
我有以下代码
class DashboardController < ApplicationController
def bookings
@bookings = Booking.all
end
end
/views/dashboard/bookings.html.erb
<%= render 'booking', :collection => @bookings %>
/views/dashboard/_booking.html.erb
<%= booking.booking_time %>
我得到以下错误
undefined method `booking_time' for nil:NilClass
但是,如果我这样做的/views/dashboard/_bookings.html.erb
<% @bookings.each do |booking| %>
<%= render 'booking', :booking => booking %>
<% end %>
我得到(正确)
2012-12-19 09:00:00 UTC
2012-12-28 03:00:00 UTC
这里发生了什么? 我真的想用:收集这里定义http://guides.rubyonrails.org/layouts_and_rendering.html