# Help with error

**URL:** <https://www.ruby-forum.com/t/help-with-error/70103>\
**Category:** Rails\
**Created:** [December 16, 2005, 6:33pm UTC](https://www.ruby-forum.com/t/help-with-error/70103 "2005-12-16T18:33:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Phelps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Scott\_Phelps](https://www.ruby-forum.com/u/Scott_Phelps)\
**Post date:** [December 16, 2005, 6:33pm UTC](https://www.ruby-forum.com/t/help-with-error/70103/1 "2005-12-16T18:33:59Z")

</div>

I am getting this error

NoMethodError in Admin#add\_to\_project

undefined method `find’ for #Project:0x249da88  
RAILS\_ROOT: script/…/config/…

Application Trace | Framework Trace | Full Trace  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active\_record/  
base.rb:1501:in `method_missing' ./script/../config/../app/controllers/admin_controller.rb:65:in`add\_to\_project’

The following code:

## application.rb

private  
def get\_project  
session[:project\_in\_progress] ||= Project.new  
end

## project\_controller.rb

def new\_general  
@project = get\_project  
@general = GeneralItem.new  
@general\_tab = “current”  
end

# Get the current Project session and

# add the current Object to it

def add\_to\_project  
@project = get\_project  
@project.find(params[:id])  
redirect\_to(:action =\> new\_license)  
end

## new\_general.rhtml

\<%= start\_form\_tag :action =\> ‘add\_to\_project’, :id =\> @project %\>

Time in  
\<%= datetime\_select (:general, :time\_in) %\>

## project.rb

attr\_reader :proj\_hash

# @items is an array to hold session Objects

def add\_item(items)  
@proj\_hash \<\< items  
end

---

<div class="post-metadata">

**Author:** ![Scott\_Phelps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Scott\_Phelps](https://www.ruby-forum.com/u/Scott_Phelps)\
**Post date:** [December 16, 2005, 6:43pm UTC](https://www.ruby-forum.com/t/help-with-error/70103/2 "2005-12-16T18:43:04Z")

</div>

Well, I added

model :project  
model :general\_item

to application.rb

But now I get this

NoMethodError in Admin#add\_to\_project

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

Here’s the session dump:

* * *

:project\_in\_progress: &id001 !ruby/object:Project  
attributes: {}  
errors: !ruby/object:ActiveRecord::Errors  
base: \*id001  
errors: {}  
general\_item:  
new\_record: true  
flash: !ruby/hash:ActionController::Flash::FlashHash {}

---

<div class="post-metadata">

**Author:** ![Scott\_Phelps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Scott\_Phelps](https://www.ruby-forum.com/u/Scott_Phelps)\
**Post date:** [December 16, 2005, 7:01pm UTC](https://www.ruby-forum.com/t/help-with-error/70103/3 "2005-12-16T19:01:08Z")

</div>

where does the error occur? could you paste the line of code where the  
nil.find is done

---

<div class="post-metadata">

**Author:** ![Scott\_Phelps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@Scott\_Phelps](https://www.ruby-forum.com/u/Scott_Phelps)\
**Post date:** [December 16, 2005, 7:10pm UTC](https://www.ruby-forum.com/t/help-with-error/70103/4 "2005-12-16T19:10:14Z")

</div>

as far as i know the table level operations are static methods, not  
instance  
methods.

@project.find

should be

Project.find

let me know if it helps.
