hi im just wondering if why the build_book_reservation is not working this is my 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 and im trying to use it here def new @book_reservation = BookReservation.new end def create @reservation = current_reservation @book_reservation=@reservation.build_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 it raises undefined methodbuild_book_reservation'' for nil:NilClass` error model/book_reservation.rb belongs_to :reservation model/reservation.rb has_one :book_reservation -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 23 April 2012 13:38, ruby LED <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> hi im just wondering if why the build_book_reservation is not working > > this is my 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 > and im trying to use it here > > def new > @book_reservation = BookReservation.new > end > > def create > @reservation = current_reservation > @book_reservation=-t6DqNsAsS6kZJ4XD+7QD7WCgeU+1il2p@public.gmane.org_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 > it raises undefined methodbuild_book_reservation'' for nil:NilClass`Then I guess current_reservation must be returning nil. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hi mr collin is my session correct in getting the current reservation? 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 23 April 2012 14:08, ruby LED <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> hi mr collin is my session correct in getting the current reservation?Please don''t top post, it makes it difficult to follow the thread, insert your replies inline at appropriate points in previous message. Thanks. I don''t know whether your session is correct. Have a look at the Rails Guide on debugging to see suggestions on how to debug your code. Then you can work out exactly where it is going wrong. Colin> 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 > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.