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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
you''re trying to call an instance method as a class method make it a class method def self.current ... end Chris On 9/1/06, Craig White <craigwhite-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote:> > 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> 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. -- Andrew Stone --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hello Craig, Surely you mean ''def Personnel.current'' since your using it as a class method .. no ? Regards Stef Craig White wrote:> 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I see - said the blind man thanks - it works Craig On Fri, 2006-09-01 at 12:13 -0400, Chris Hall wrote:> you''re trying to call an instance method as a class method > > make it a class method > > def self.current > ... > end > > Chris > > On 9/1/06, Craig White <craigwhite-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote: > > > > 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Fri, 2006-09-01 at 12:22 -0400, Andrew Stone wrote:> > 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".---- it''s sometimes amazing that I have gotten as much done as I have - even after reading/re-reading AWDWR and R4R ;-) ----> > 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.---- No, in this instance, I needed a list of only ''current'' personnel (i.e. termination date is NULL and employee types and not volunteers/board members, etc. Thanks, self.current was indeed the solution. Craig --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---