Hi all, I am writing a simple shopping cart which will consist of a single class. There will be no DB table for carts so I do not want to make my Cart a model. But where do I place my Cart class so that I can access it in my controllers? I want to be able do do things like this (for instance in a shop controller): def add_to_cart @session[''cart''].add(article_id, amount) end where the cart would have been created like: @session[''cart''] = Cart.new Many thanks in advance! -- Nicky
It''s still a model in the MVC sense so keep it in the models directory On Sun, 6 Mar 2005 21:38:36 +0100, Nickolay Kolev <nmkolev-OhoefBWHl6Eb1SvskN2V4Q@public.gmane.org> wrote:> Hi all, > > I am writing a simple shopping cart which will consist of a single > class. There will be no DB table for carts so I do not want to make my > Cart a model. But where do I place my Cart class so that I can access > it in my controllers? > > I want to be able do do things like this (for instance in a shop > controller): > > def add_to_cart > @session[''cart''].add(article_id, amount) > end > > where the cart would have been created like: > > @session[''cart''] = Cart.new > > Many thanks in advance! > > -- Nicky > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Mar 6, 2005, at 21:38 Uhr, Nickolay Kolev wrote:> Hi all, > > I am writing a simple shopping cart which will consist of a single > class. There will be no DB table for carts so I do not want to make my > Cart a model. But where do I place my Cart class so that I can access > it in my controllers?i would definitely put it in models. it IS a model. models don''t always require persistence.
> i would definitely put it in models. it IS a model. models don''t > always require persistence.I suppose I just don''t have to inhertit form ActiveRecord::Base then? -- Nicky
Nickolay Kolev schrieb:>> i would definitely put it in models. it IS a model. models don''t >> always require persistence. > > > I suppose I just don''t have to inhertit form ActiveRecord::Base then?yep ;) Sascha
One thing I noticed just now... Whenever I add a method to my Cart class I have to restart Apache for rails to pick up the changes. I then have to restart my browser, because fcgi has cleared all its objects on server shutdown. Is this normal? I am running Apache 2.0.52 with fcgi on OSX. -- Nicky
On Sunday 06 March 2005 21:17, Nickolay Kolev wrote:> Whenever I add a method to my Cart class I have to restart Apache for > rails to pick up the changes. I then have to restart my browser, > because fcgi has cleared all its objects on server shutdown. Is this > normal?Yep. It''s easier to develop using the server script (script/server directory of your rails project). Or, more generally, CGI etc. FCGI and mod_python etc. are better for final production code that doesn''t change much. As always, develop, make sure it works, and worry about speeding it up later. -- Lee.
> Yep. It''s easier to develop using the server script (script/server > directory > of your rails project). Or, more generally, CGI etc. FCGI and > mod_python > etc. are better for final production code that doesn''t change much. As > always, develop, make sure it works, and worry about speeding it up > later.OK, thanks for clearing this up. -- Nicky
On Sunday 06 March 2005 21:29, Nickolay Kolev wrote:> > of your rails project). Or, more generally, CGI etc. FCGI and > > mod_python > OK, thanks for clearing this up.Very welcome :) p.s.: sorry everyone, I meant mod_ruby of course :D -- Lee.
I find I can make changes in my code, even when using fast_cgi, if I am operating in my "development" environment. This is not the case if I am in "production" environment. ruby script/server -e development (webrick) FastCgiServer /mypath/public/dispatch.fcgi -initial-env RAILS_ENV=development (fast_cgi on Apache) On Sun, 6 Mar 2005 21:34:49 +0000, Lee Braiden <jel-OMY0mCUCxqbPG/DoapTOmA@public.gmane.org> wrote:> On Sunday 06 March 2005 21:29, Nickolay Kolev wrote: > > > of your rails project). Or, more generally, CGI etc. FCGI and > > > mod_python > > OK, thanks for clearing this up. > > Very welcome :) > > p.s.: sorry everyone, I meant mod_ruby of course :D > > -- > Lee. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
scott-aZyoR/gAeCAw/bTnQTrD9Q@public.gmane.org
2005-Mar-06 21:53 UTC
Re: Where to place custom classes?
You should use require_dependency rather then require this will reload the dependency when it changes. On March 6, 2005 02:17 pm, Nickolay Kolev wrote:> One thing I noticed just now... > > Whenever I add a method to my Cart class I have to restart Apache for > rails to pick up the changes. I then have to restart my browser, > because fcgi has cleared all its objects on server shutdown. Is this > normal? > > I am running Apache 2.0.52 with fcgi on OSX. > > -- Nicky > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
> You should use require_dependency rather then require > > this will reload the dependency when it changes.If I have my cart.rb i the models directory, I do not have to require anything, the controller finds it automagically. I will check how it behaves when I use require_dependency. How do I set my production environment? I know I am in development right now, as this is the only database I have defined in database.yml. :-) How do I set it to production at the and and what changes would that bring? -- Nicky
* Nickolay Kolev <nmkolev-OhoefBWHl6Eb1SvskN2V4Q@public.gmane.org> [0321 06:21]:> >You should use require_dependency rather then require > > > >this will reload the dependency when it changes. > > If I have my cart.rb i the models directory, I do not have to require > anything, the controller finds it automagically. I will check how it > behaves when I use require_dependency. > > How do I set my production environment? I know I am in development > right now, as this is the only database I have defined in database.yml. > :-) How do I set it to production at the and and what changes would > that bring?You set RAILS_ENV=production in your environment. (or use the -e flag if running webrick, last time I checked that overrode the environment setting). -- ''...and then we wrote scripts to write the configs for us, and using these scripts, we made mistakes in a faster, more automated manner.'' -- A Gentle Introduction to Cricket, on MRTG configuration Rasputin :: Jack of All Trades - Master of Nuns