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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:11:01+00:00 2026-05-23T14:11:01+00:00

Currently working on a project, and have ran into a dead end with the

  • 0

Currently working on a project, and have ran into a dead end with the following error:

You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each

I did some research and found that it could possibly be because of pluralization. The code follows:

   <h1>Listing Expectedd Schedules</h1>

<table>
    <tr>
        <th>From</th>
        <th>To</th>
        <th>State</th>
        <th>Delivery Time</th>
        <th>Collection Time</th></>
        <th>Edit</th>
    </tr>

    <% @schedules.each do |schedule| %>

    <tr>
        <td><%= schedule.from_location_id %></td>
        <td><%= schedule.to_location_id %></td>
        <td><%= schedule.schedule_type %></td>
        <td><%= schedule.delivery_time %></td>
        <td><%= schedule.collection_time%></td>
    </tr>
    <% end %>
</table>

I changed the following line <% @schedules.each do |schedule| % to <% @schedule.each do |schedule| %`. However when that change is made I get an No method defined method that explains that I have not defined the variable each. This is rather confusing, trying many different ways and unable to get around this.

Schedules Controller

class SchedulesController < ApplicationController
  before_filter :authenticate, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
  # GET /schedules
  # GET /schedules.xml
  def index
    @title = "Schedules"
    @schedules = Schedule.all

     respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @schedules }
    end
  end

  # GET /schedules/1
  # GET /schedules/1.xml
  def show
    @title = "Show schedule"
    @schedule = Schedule.find(params[:id])


    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @schedule }
    end
  end

  def allowed
    @title = "Allowed schedules"
    @schedule = Schedule.new
    @clients = Client.find(:all)

    respond_to do |format|
      format.html #allowed.html.erb
      format.xml { render :xml => @schedule }

    end
  end

  def expected
    @title = "Expected schedule"
    #@schedule = Schedule.find(params[:all])
    @schedule = Schedule.new

    respond_to do |format|
      format.html #allowed.html.erb
      format.xml { render :xml => @schedule }
    end
  end

  # GET /schedules/new
  # GET /schedules/new.xml
  def new
    @title = "New schedule"
    @schedule = Schedule.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @schedule }
    end
  end

  # GET /schedules/1/edit
  def edit
    @title = "Edit schedule"
    @schedule = Schedule.find(params[:id])
  end

  def complete
    @title = "Complete schedule"
    @schedule = Schedule.new
  end
  # POST /schedules
  # POST /schedules.xml
  def create
    @schedule = Schedule.new(params[:schedule])

    respond_to do |format|
      if @schedule.save
        format.html { redirect_to :action =>  "expected", :notice => 'Schedule was successfully created.' }
        format.xml  { render :xml => @schedule, :status => :created, :location => @schedule }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @schedule.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /schedules/1
  # PUT /schedules/1.xml
  def update
    @schedule = Schedule.find(params[:id])

    respond_to do |format|
      if @schedule.update_attributes(params[:schedule])
        format.html { redirect_to(@schedule, :notice => 'Schedule was successfully updated.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @schedule.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /schedules/1
  # DELETE /schedules/1.xml
  def destroy
    @schedule = Schedule.find(params[:id])
    @schedule.destroy

    respond_to do |format|
      format.html { redirect_to(schedules_url) }
      format.xml  { head :ok }
    end
  end

  # Gets the status for the given weekday out of the schedule record
  def self.status_for_wday( schedule, wday )
    case wday
    when 0
      schedule.sun_status
    when 1
      schedule.mon_status
    when 2
      schedule.tue_status
    when 3
      schedule.wed_status
    when 4
      schedule.thu_status
    when 5
      schedule.fri_status
    when 6
      schedule.sat_status
    else
    ""
    end
  end

  def self.create_orders
    schedules = Schedule.all

    schedules.each do |schedule|

    # Get current weekday
      base_datetime = DateTime.now
      curday = base_datetime.wday

      # check the schedule for each weekday
      (0..6).each do |wday|
        if status_for_wday( schedule, wday ) == "E"
          offsetdays = wday - curday
          offsetdays += 7 if offsetdays <= 0

          # Get the next delivery and collection datetime for the given schedule
          offset_datetime = base_datetime + offsetdays
          del_datetime = DateTime.parse( offset_datetime.strftime( "%Y-%m-%d " ) + schedule.delivery_time )
          col_datetime = DateTime.parse( offset_datetime.strftime( "%Y-%m-%d " ) + schedule.collection_time )

          # Try and find a matching order
          order = Order.where( :client_id => schedule.client_id,
          :order_type => schedule.schedule_type,
          :from_location_id => schedule.from_location_id,
          :to_location_id => schedule.to_location_id,
          'delivery_datetime' => del_datetime.strftime( "%Y-%m-%d %H:%M:%S.%6N" ),
          'collection_datetime' => col_datetime.strftime( "%Y-%m-%d %H:%M:%S.%6N" ) )

          # Create the order unless it already exists
          unless order.any?
            order = Order.create!( :status => "Estimated",
            :client_id => schedule.client_id,
            :order_type => schedule.schedule_type,
            :from_location_id => schedule.from_location_id,
            :to_location_id => schedule.to_location_id,
            :estimated_pallets => schedule.estimated_pallets,
            :delivery_datetime => del_datetime,
            :collection_datetime => col_datetime )
          end
        end
      end
    end
  end

  private

  def authenticate
    deny_access unless signed_in?
  end
end
  • 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-23T14:11:02+00:00Added an answer on May 23, 2026 at 2:11 pm

    I see nothing wrong here, and think it should work – so are you setting the @schedules collection in the controller? – the combination of error messages suggests you probably didn’t – maybe try putting a print statement in the view to see what @schedules actually is …

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

Sidebar

Related Questions

I have been working on keeping things object oriented for my project. Currently, I'm
I'm currently working on a medium-sized web project, and I've ran into a problem.
While working on a project I ran into the following Issue, in my CoreData
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I have a project that I'm currently working on but it currently only supports
Im currently working on a grizzly, spring and jersey project and i have encountered:
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
In the project I am currently working on, we have the need to develop
Hi Currently i am working on a rails project . where i have to
I'm currently working on a school project in Eclipse (We have just started using

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.