Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:31:39+00:00 2026-06-02T18:31:39+00:00

hi im just wondering if why the session cant find my reservation upon refresh

  • 0

hi im just wondering if why the session cant find my reservation upon refresh and used it in a other controller

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 us 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:31:43+00:00Added an answer on June 2, 2026 at 6:31 pm

    Cause of the error is you never set session but you tried to access it.In your application controller use

    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
    

    In your controller

     def new
       @book_reservation = BookReservation.new
     end
    
    def create
      @reservation = Reservation.find(params[:reservation_id])
      if @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
       else
          render :action => 'new'
       end
    

    Then whenever you need you can use current_reservation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering if there's a way to dump all of the values of $this->session->userdata()
I'm just wondering if the same thread is used for each session, or if
Just wondering for user permission check, Should you keep the permission in the session
Just wondering if anyone can optimize this usortMonths() function to be better? Basically I
I just spent 3 hours wondering why I couldn't start a session, then realised
Just wondering if there is any easy way to start a debugging session that
I am new to Flex. I am just wondering how to manage session and
Just wondering whether an object can self-destruct. Consider this situation. An object that extends
Just wondering whether an object can self-destruct. Consider this situation. An object that extends
just wondering if there is a way to reduce the amount of code needed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.