Welcome Guest | Login

NoMethodFound error for new method in model

I recently added a method I called 'component_filter' to one of my models and uploaded it to my app.  When I try to access the method, I get the following: "NoMethodError (undefined method `component_filter' for #):" in my log.  Thinking that I just needed to restart my rails app, I ran "killall -usr1 dispatch.fcgi" using pUTTY, but I continue to get the error.  Thinking that the model may still be cached somehow, I added an extra validation, uploaded the model, and tried something that should have raised a validation error, but it did not.  This still makes me think that the model is cached, but I don't understand why or what else may be going on.

Thanks for your help!

2006-10-24 10:39 AM

How are you calling the method and what is the general  code structure (i.e. just paste the code) you're using for it in the model?

If you run killall then that will clear everything out unless you have purposely set up other caching options.  

2006-10-24 12:08 PM

Thanks, Brian.  Here is the complete code for my model:

class Formula < ActiveRecord::Base
 belongs_to :category
 has_many :formula_details, :order => :position, :dependent => :destroy
 validates_presence_of :name, :description
 validates_uniqueness_of :name, :description
 validates_numericality_of :butterfat, :milk_solids_non_fat, :sucrose, :glucose, :weight_per_gallon
 acts_as_list

 
 def component_filter
   if read_attribute("sucrose").eql? 0.0 then
     filter = "sucrose = 0.0"
   end
   if read_attribute("glucose").eql? 0.0 then
     filter = "glucose = 0.0"
   end
   if read_attribute("sucrose").eql? 0.0 and read_attribute("glucose").eql? 0.0 then
     filter = 'sucrose = 0.0 AND glucose = 0.0'
   end
 end
end


In my formulas_controller, I'm calling the method like so:
@formula.component_filter
to return a string like:
"sucrose = 0.0 AND glucose = 0.0" which I use to create a subset of ingredients used in a partial, like so:

@ingredients = BaseIngredient.find(:all, :order => 'position', :conditions => @formula.component_filter)

I haven't made any changes to the caching options.

2006-10-24 12:31 PM

Hmmm - that looks like it should work to me.....can you tweak the def to stop causing the error?  Can you reposition the location of the @formula.component_filter? i.e. stick it in another variable?  -- you probably tried all this and I'm afraid I may not be much help...I'll keep thinking and let you know...

2006-10-24 12:39 PM

Hmmm. When I reposition I get the same error, just on a different line.  And remember, there's a validation that I added that isn't working either.  It acts like it's not there, just like the method...   Would it be ok if I turn off caching in the /config/environments/production.rb and see what happens?

2006-10-24 12:57 PM

yeah of course, give that a try.  I'm just curious about how much you have to delete from that model before it starts working again.  

2006-10-25 03:27 AM

Got it!!  My stupid mistake.  At some point I must have inadvertently uploaded my model to my app/controllers/ directory.  The app must be finding that one rather than the latter one in the app/models dir.  Lesson learned.  Thanks for your time, guys.

2006-10-25 07:51 AM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!