這是如此簡單,它不應該是一個問題,但我不明白這裏發生了什麼。Rails渲染部分:集合
我有以下代碼
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
這應該是被接受的答案! –