# Why Getting 'NoMethodError' Error

**URL:** <https://www.ruby-forum.com/t/why-getting-nomethoderror-error/126589>\
**Category:** Rails\
**Created:** [January 19, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/why-getting-nomethoderror-error/126589 "2008-01-19T23:17:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![skiz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e99b99/32.png) [@skiz](https://www.ruby-forum.com/u/skiz)\
**Post date:** [January 19, 2008, 11:17pm UTC](https://www.ruby-forum.com/t/why-getting-nomethoderror-error/126589/1 "2008-01-19T23:17:39Z")

</div>

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!!

Thanks

Josh

## Here is relevant code:

index.rhtml(view)

 \<%= 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” %\>  
\<%end%\>

## 

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  
else  
render :action =\> :index  
end

end  
def index  
@categories = FullTimeCategory.find(:all, :order =\> “display\_order”)  
end

## end

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”)  
end

end
