这很简单,它不应该是一个问题,但我不明白这里发生了什么。
我有以下代码
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
这里发生了什么?我真的很想使用这里定义的 :collection http://guides.rubyonrails.org/layouts_and_rendering.html