I have a file my_library.rb in the lib folder. class MyLibrary def auth(username,password) end end I know it doesn''t do anything yet, but I wanted to eliminate the possibility of errors in the method. class MyController < ApplicationController require ''my_library'' def index MyLibrary.auth("username","password") end ... end As I try to invoke the auth method from the controller above I get this exception: NoMethodError in Person summary requestsController#index undefined method `auth'' for MyLibrary:Class RAILS_ROOT: /Users/peterivie/AptanaProjects/AMC Application Trace | Framework Trace | Full Trace app/controllers/person_summary_requests_controller.rb:16:in `index'' -e:2:in `load'' -e:2 I also tried MyLibrary::auth("username","password") I am new to Ruby so I am probably missing something obvious. I am trying to create some code to download xml from a (non-rails) REST API. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Wed, 9 Apr 2008, cumom wrote:> > I have a file my_library.rb in the lib folder. > class MyLibrary > def auth(username,password) > end > end > > I know it doesn''t do anything yet, but I wanted to eliminate the > possibility of errors in the method. > > > class MyController < ApplicationController > require ''my_library'' > def index > MyLibrary.auth("username","password") > end > ... > end > > As I try to invoke the auth method from the controller above I get > this exception: > > NoMethodError in Person summary requestsController#index > > undefined method `auth'' for MyLibrary:Class > RAILS_ROOT: /Users/peterivie/AptanaProjects/AMC > > Application Trace | Framework Trace | Full Trace > app/controllers/person_summary_requests_controller.rb:16:in `index'' > -e:2:in `load'' > -e:2 > > I also tried MyLibrary::auth("username","password") > > I am new to Ruby so I am probably missing something obvious. I am > trying to create some code to download xml from a (non-rails) REST API.You''ve defined auth as an instance method, not a class method. Try this: class MyLibrary def self.auth ... etc. David -- Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS April 14-17 New York City INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin See http://www.rubypal.com for details and updates! --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the quick response. Your suggestion and a server reboot fixed it. That''s probably something I would understand better if I had payed more attention in my class on object oriented programming years ago. I will assume the difference is that class methods can be called without creating an actual object (or instance of the class). That makes sense. Thanks again, I should have asked about 4 hours of head beating ago. On Apr 9, 12:04 pm, "David A. Black" <dbl...-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote:> Hi -- > > > > On Wed, 9 Apr 2008, cumom wrote: > > > I have a file my_library.rb in the lib folder. > > class MyLibrary > > def auth(username,password) > > end > > end > > > I know it doesn''t do anything yet, but I wanted to eliminate the > > possibility of errors in the method. > > > class MyController < ApplicationController > > require ''my_library'' > > def index > > MyLibrary.auth("username","password") > > end > > ... > > end > > > As I try to invoke the auth method from the controller above I get > > this exception: > > > NoMethodError in Person summary requestsController#index > > > undefined method `auth'' for MyLibrary:Class > > RAILS_ROOT: /Users/peterivie/AptanaProjects/AMC > > > Application Trace | Framework Trace | Full Trace > > app/controllers/person_summary_requests_controller.rb:16:in `index'' > > -e:2:in `load'' > > -e:2 > > > I also tried MyLibrary::auth("username","password") > > > I am new to Ruby so I am probably missing something obvious. I am > > trying to create some code to download xml from a (non-rails) REST API. > > You''ve defined auth as an instance method, not a class method. Try > this: > > class MyLibrary > def self.auth ... etc. > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > ADVANCING WITH RAILS April 14-17 New York City > INTRO TO RAILS June 9-12 Berlin > ADVANCING WITH RAILS June 16-19 Berlin > Seehttp://www.rubypal.comfor details and updates!--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---