Hi, I''m trying to verify that a parameter is an instance of a specific class in Rails: def schedule(action, *args) if arg.is_a? Aircraft ... end end I''m doing this in a library class (the file is in lib/) and I get an uninitialized constant Aircraft error. Aircraft is a model class, with a corresponding aircraft.rb file in app/models. Can I use model classes and instances in a library? How? Thanks, Xtian --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How and where are you executing the code in this lib from, rake task, script/console, etc.? On Nov 28, 12:10 pm, Christian Lescuyer <christian.lescu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m trying to verify that a parameter is an instance of a specific > class in Rails: > > def schedule(action, *args) > if arg.is_a? Aircraft > ... > end > end > > I''m doing this in a library class (the file is in lib/) and I get an > uninitialized constant Aircraft error. Aircraft is a model class, with > a corresponding aircraft.rb file in app/models. > > Can I use model classes and instances in a library? How? > > Thanks, > Xtian--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for your answer: I tried to run the app in the browser: it works! So it doesn''t work in RSpec. I didn''t try the code in the browser at first as I''m trying to do TDD. Still stuck there, though. Christian --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sounds like you just need a line like this in the top of the lib file: require ''app/models/aircraft'' If its already loaded (ie: running script/server) nothing will change, but if its not already loaded (I don''t use RSpec, but it sounds like its not autoloading classes) this should fix it. You might need to play with the path and do something like this: require File.dirname(__FILE__)+''/../app/models/aircraft'' On Nov 29, 7:45 am, Christian Lescuyer <christian.lescu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for your answer: I tried to run the app in the browser: it > works! > So it doesn''t work in RSpec. I didn''t try the code in the browser at > first as I''m trying to do TDD. Still stuck there, though. > > Christian--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---