Why Getting 'NoMethodError' Error

Hi. I am new to rails and am hoping someone can help me understand why I
am getting a certain error. I have gone through the Agile Web
Development Book and am now trying to build a basic app (job board) to
try something “real world.”

I have a form where I collect the job details. In the form is a select
statement which pulls categories from the DB. The categories are in an
instance variable that I create in the index method. When I load the
form, the categories are loaded correctly. However, then I added
validation, and when a validator kicks, I get a NoMethodError (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.inject).

It points me to the select statement in my form as the culprit. So, it
seems that the instance variable is not populated, after the error, when
its part of the index method. I think I confirmed this by putting the
instance variable inline, before the select statement, in the form.
Then everything worked as expected.

I really am just trying to learn what I am doing wrong and why that
isn’t filling the instance variable with the categories. Any education
is appreciated!!



Here is relevant code:


<%= error_messages_for 'full_time_job' %> Enter Job <%form_for :full_time_job, :url => { :action => :save_job} do |form|%>

Company <%= form.text_field :company, :size =>100 %>

Website <%= form.text_field :url, :size =>200 %>

Job Title <%= form.text_field :title, :size =>255 %>

Job Location <%= form.text_field :location, :size =>100 %>

Description <%= form.text_area :description, :rows =>3, :cols =>40 %>

Category <%=form.collection_select (:fulltimecategory_id,@categories,:id,:name) %>

How to Apply <%= form.text_field :apply, :size =>100 %>

<%= submit_tag “Save Job”, :class => “submit” %>

full_time_add_controller.rb (controller)
class FullTimeAddController < ApplicationController
def save_job
@full_time_job = FullTimeJob.new(params[:full_time_job])
if @full_time_job.save
render :action => :index

def index
@categories = FullTimeCategory.find(:all, :order => “display_order”)


full_time_job.rb (Model)
class FullTimeJob < ActiveRecord::Base
belongs_to :full_time_category
validates_presence_of :company
def self.find_jobs
find(:all, :order => “created_at”)