James Smith
2007-Jan-28 13:36 UTC
Where do i put classes that i want to use in Controller??
Hello, Can someone please help me.. I would like to know where i should put classes that i need to use within my controller? And how are they accessible to the controller? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Elliott Blatt
2007-Jan-28 14:29 UTC
Re: Where do i put classes that i want to use in Controller?
James Smith wrote:> Hello, > > Can someone please help me.. > > I would like to know where i should put classes that i need to use > within my controller? > > And how are they accessible to the controller?If it is a controller class, I''d put it in your app/controllers directory. Model classes in app/models, etc. app/contollers/your_controller.rb def YourController < ActiveConroller ModelClass.method() end app/models/model_class.rb def ModelClass < ActiveRecord::Base def method end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
James Smith
2007-Jan-28 16:59 UTC
Re: Where do i put classes that i want to use in Controller?
Elliott Blatt wrote:> If it is a controller class, I''d put it in your app/controllers > directory. Model classes in app/models, etc.It is neither.. Its just an additional class that i need to create objects for use within my controller, any ideas?? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Jan-28 17:07 UTC
Re: Where do i put classes that i want to use in Controller?
Hi -- On Sun, 28 Jan 2007, James Smith wrote:> > Elliott Blatt wrote: > >> If it is a controller class, I''d put it in your app/controllers >> directory. Model classes in app/models, etc. > > It is neither.. Its just an additional class that i need to create > objects for use within my controller, any ideas??It sounds like a candidate for a file in lib/ . David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Steve Bartholomew
2007-Jan-28 17:08 UTC
Re: Where do i put classes that i want to use in Controller?
> Its just an additional class that i need to create > objects for use within my controller, any ideas??If you create a class and put it in lib/, you''ll be able to access it from anywhere in your application - including controllers. Just name the file after the class name i.e. MyClass should be in lib/ my_class.rb. If you''re using 1.2, rails will include the file automatically. If you''re still on an earlier version, you''ll need to add a require line in yourself in environment.rb (require ''my_class''). Hope that helps, Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
James Smith
2007-Jan-28 17:27 UTC
Re: Where do i put classes that i want to use in Controller?
> Hope that helps,Yes, thanks very much. One last question, if thats OK? When my application starts i need to do some basic setup work. This just involves calling a method that creates some objects, that are stored in the @session, based on data retrieved from the database. Can you advise me as to where this method should be called from (just the index of the first controller??) and where this ''setup'' method should be within my rails directory structure? Thanks again -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Steve Bartholomew
2007-Jan-28 21:32 UTC
Re: Where do i put classes that i want to use in Controller?
> where this > ''setup'' method should be within my rails directory structure?What I would do is add a before_filter to your ApplicationController: class ApplicationController < ActionController:Base before_filter :setup private def setup if !session[:my_variable] # get data and edit session end end end Just to note, you should use the ''session'' method to access the session data rather than the instance variable ''@session''. You should also consider whether or not you really need to store objects in the session as it can cause issues. It''s best to keep the session small if you can. Hope that helps, Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---