undefined method `current' for Personnel:Class

I can't quite figure out how I can make this work properly.

I'm in my login_controller.rb

If I use   cond = EZ::Where::Condition.new   cond = "term_date IS NULL".to_c + c{employment_type === ['CLIENT', 'CSW', 'F/T','P/T', 'INT', 'PRN']}   @personnel = Personnel.find(:all,     :conditions => cond.to_sql,     :order => 'last_name, first_name')

This works but is not very dry since I use this in multiple places.

So in my personnel.rb model, I have something identical...   def current     cond = EZ::Where::Condition.new     cond = "term_date IS NULL".to_c + c{employment_type === ['CLIENT',      'CSW', 'F/T','P/T', 'INT', 'PRN']}     Personnel.find(:all,      :conditions => cond.to_sql,      :order => 'last_name, first_name')   end

but if I try to use     @personnel = Personnel.current

in my login_controller.rb, I get the 'undefined method 'current' for Personnel:Class error - even if I 'require "personnel" in my login.rb model (which I wouldn't think necessary since login.rb 'has_one :personnel')

Why doesn't the definition in the personnel model work in another controller?

Craig

you're trying to call an instance method as a class method

make it a class method

def self.current   ... end

Chris

def current cond = EZ::Where::Condition.new cond = “term_date IS NULL”.to_c + c{employment_type === [‘CLIENT’,

 'CSW', 'F/T','P/T', 'INT', 'PRN']}
Personnel.find(:all,
 :conditions => cond.to_sql,
 :order => 'last_name, first_name')

end

but if I try to use @personnel = Personnel.current

You’ve defined current as an instance method, but are trying to access it as a class method. One way to define it as a class method is to:

def self.current … end

then Personnel.current will be “seen”.

On a side note, you may want to use Personnel.find(:first) as Personnel.find(:all) will return an array and I think you just want a single personnel instance.

Hello Craig,     Surely you mean 'def Personnel.current' since your using it as a class method .. no ?         Regards     Stef

Craig White wrote:

I see - said the blind man

thanks - it works

Craig

          def current             cond = EZ::Where::Condition.new             cond = "term_date IS NULL".to_c + c{employment_type ===         ['CLIENT',              'CSW', 'F/T','P/T', 'INT', 'PRN']}             Personnel.find(:all,              :conditions => cond.to_sql,              :order => 'last_name, first_name')           end                  but if I try to use             @personnel = Personnel.current

You've defined current as an instance method, but are trying to access it as a class method. One way to define it as a class method is to:

def self.current ... end

then Personnel.current will be "seen".