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 7567091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:34:40+00:00 2026-05-30T14:34:40+00:00

Could some explain to me why I may well be getting the following error

  • 0

Could some explain to me why I may well be getting the following error every time I try to create a booking.

NoMethodError in BookingsController#create

undefined method `diary_slot_day_time_path' for nil:NilClass

I have the following code in my controller:

class BookingsController < PortalController

  # GET /bookings
  # GET /bookings.json
  def index

    session[:booking_context] = 'index'

    if current_user.is_booking_manager? 
    #  @bookings = Booking.all
    # @bookings = Booking.filter(params[:search], [:reference_number, :company_id])
     @bookings = Booking.includes(:company).filter(params[:search], [:reference_number, "companies.name"])
    @main_heading = 'Bookings'
    else
      @bookings = current_user.company.bookings
    @main_heading = "#{current_user.company.name} Bookings"
    end

    respond_to do |format|
      format.html # index.html.erb
    end
  end

  # GET /bookings/1
  def show
    @booking = Booking.find(params[:id])
    goto_booking(@booking)
  end

  # GET /bookings/1/edit
  def edit
    @booking = Booking.find(params[:id])
    @main_heading = 'Edit Booking'
  end

  # Go to booking
  def goto_booking(booking)

    site = @booking.site
    slot_day = @booking.slot_day
    slot_time = @booking.slot_time

    # don't need to check slot_time because it is optional
    if session[:booking_context] and session[:booking_context] == 'diary' and site and slot_day
      # Go the diary page
      respond_to do |format|
        format.html { redirect_to diary_slot_day_time_path(site, slot_day, slot_time) }
      end
    else

      # Go to booking edit page
      respond_to do |format|
        format.html { redirect_to edit_booking_path(@booking) }
      end
    end
  end

  # POST /bookings
  def create
    @booking = Booking.new(params[:booking])
    unless @booking and @booking.slot_time and @booking.slot_time.number_of_free_slots > 0
      flash[:notice] = 'Slot no longer available'
      redirect_to :back
      return
    end

    if @booking.save
      flash[:notice] = 'Booking was successfully created'
      goto_booking(@booking)
    else
      @main_heading = 'Review New Booking'
      respond_to do |format|
        format.html { render action: "new" }
      end
    end
  end

  # PUT /bookings/1
  def update
    @booking = Booking.find(params[:id])
    if @booking.update_attributes(params[:booking])
      flash[:notice] = 'Booking was successfully updated'
      goto_booking(@booking)
    else
      @main_heading = 'Review Booking'
      respond_to do |format|
        format.html { render action: "edit" }
      end
    end
  end

  def confirmation
    begin
      @booking = Booking.find(params[:booking][:id])
      @booking.update_attributes(params[:booking])
      if params[:make_unexpected]
        @booking.provisional_appointment = nil
        @booking.save!
      end
      @booking.update_slot!
      success = true
    rescue => e
      flash[:error] = e.message
      success = false
    end

    if success
      flash[:notice] = 'Booking confirmed'
      respond_to do |format|
        format.html { redirect_to booking_path(@booking) }
      end      
    else
      redirect_to :back
    end
  end

  # DELETE /bookings/1
  def destroy
    @booking = Booking.find(params[:id])

    if @booking
      if session[:booking_context] and session[:booking_context] == 'diary'
        site = @booking.site
        slot_day = @booking.slot_day
        slot_time = @booking.slot_time
      end

      if @booking.destroy
        flash[:notice] = 'booking removed'
      else
        flash[:error] = 'could not remove booking'
      end
    end

    # don't need to check slot_time; that's optional
    if site and slot_day

      # redirect to diary page
      respond_to do |format|
        format.html { redirect_to diary_slot_day_time_path(site, slot_day, slot_time) }
      end
    else

      # redirect to booking index
      respond_to do |format|
        format.html { redirect_to bookings_url }
      end
    end
  end

  def diary_slot_day_time_path(*args)
    @template.diary_slot_day_time_path(*args)
  end

end

I think that potentially it is something to do with a routing error I may well be wrong. This is my full trace error: Pastie. I have looked at the trace which indicates to me that there is something wrong with my go_to_booking, create methods.

  • 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-05-30T14:34:41+00:00Added an answer on May 30, 2026 at 2:34 pm

    Why do you have this method defined at the bottom of your controller?

    def diary_slot_day_time_path(*args)
      @template.diary_slot_day_time_path(*args)
    end
    

    This is attempting to reference an undefined instance variable called @template, which is why you’re getting that error.

    You should be defining this method in your routes, by using nested routes like this:

    match '/diary/:day/:time', :to => "some_controller#some_action", :as => "diary_slot_day_time"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam getting the following error , could some one help me how to fix
Could some one explain to me the meaning of the following Ruby code? (I
Could anyone explain with some examples when it is better to call functions by
Could some one guide me to create a APS logon token in .Net programmatically?
Wondering if I could get some advice and direction on this following requirement: Need
Found this which may explain some of my problems - MSDN Post I have
The concept of narrowing seems pretty straight-forward. However, could someone please explain why some
Could some one tell me how to capture SOAP messages passed between the client
I'm looking for an online introduction to occam 2. Could some one help me?
I could use some help writing a regular expression. In my Django application, users

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.