Forum: Ruby on Rails Help with error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Scott Phelps (Guest)
on 2005-12-16 19:33
(Received via mailing list)
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 %>
<p>
<label for="time_in">Time in</label>
<br/><%= datetime_select (:general, :time_in) %>
</p>

project.rb
----------
attr_reader :proj_hash

# @items is an array to hold session Objects
def add_item(items)
   @proj_hash << items
end
Scott Phelps (Guest)
on 2005-12-16 19:43
(Received via mailing list)
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 {}
Cyril Ucron D. (Guest)
on 2005-12-16 20:01
(Received via mailing list)
where does the error occur? could you paste the line of code where the
nil.find is done
Cyril Ucron D. (Guest)
on 2005-12-16 20:10
(Received via mailing list)
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.
This topic is locked and can not be replied to.