嗨我只是想知道,如果,为什么会找不到刷新时我的预订,并在其他控制器未定义的方法`build_book_reservation
用它,这是我的ApplicationController
helper :all # include all helpers, all the time
private
def current_reservation
@reservation ||= Reservation.find(session[:reservation_id]) if session[:reservation_id]
#last assigned value will be returned as default.
end
def create_reservation_session(id)
session[:reservation_id] = id
end
def destroy_reservation_session
session[:reservation_id] = nil
end
和我在这里想给我们这
def new
@book_reservation = BookReservation.new
end
def create
@reservation = current_reservation
@[email protected]_book_reservation(params[:book_reservation])
if @book_reservation.save
#If success set session
create_reservation_session(@reservation.id)
#redirect_to root_url, :notice => "Successfully created book reservation."
else
render :action => 'new'
end
end
它提出undefined method
build_book_reservation”的零:NilClass`错误
模型/ book_reservation.rb
belongs_to :reservation
模型/ reservation.rb
has_one :book_reservation
嗨试过你的建议,它现在工作它引发不同的错误'未定义的方法'build_book_reservation'为零:NilClass'这可能是一个主题只是想知道如果你知道为什么发生这种情况只是编辑我的职位,在此先感谢:) – Led 2012-04-23 12:09:03
在您的创建方法中添加@reservation并告诉我您获得了什么输出? – 2012-04-23 12:15:48
怎么样放一个日志?对不起im新的红宝石:( – Led 2012-04-23 12:17:25