steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2006-Nov-20 21:14 UTC
Rails caching the model - is there a way to disable it or clear the cache code?
Hi, so basically I''m starting with Rails (moving from Coldfusion/Java). I''m following the Agile development with rails book, and I have this method in my model, called ''add_to_cart'', called from the controller. Now I was modifying this method, reloaded the page, and noticed my changed were not being taken into account. I tried clearing the browser cache, nothing. I tried adding debug message in the method body, nothing. I tried DELETING THE WHOLE METHOD - nothing - it was still functionning as if the method was still there. In CF it''s called ''bytecode templates'' and they can be easily cleared when CF chokes on them. I was wondering if there is such a think in rails - or even better, a way to prevent rails from caching the model at all when in ''development'' mode. TIA! --~--~---------~--~----~------------~-------~--~----~ 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.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2006-Nov-20 21:27 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
Well actually now I''m at the point where I have to restart the server whenever I need to update the model... it''s getting annoying :( --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brian Hogan
2006-Nov-20 21:36 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
By default, in development mode, your models will always reload on every request. It sounds like your environment is not set up quite right. I''d like to hear more about your enviornment... OS, ruby version, whether you''re using WEBrick or Apache, and what version of the Agile book you''re using. On 11/20/06, steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org <steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > > Well actually now I''m at the point where I have to restart the server > whenever I need to update the model... it''s getting annoying :( > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mathias Wittlock
2006-Nov-20 21:38 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
On 11/20/06, steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org <steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > Well actually now I''m at the point where I have to restart the server > whenever I need to update the model... it''s getting annoying :(Have you accidentally switched your application into Production environment? That''s when this caching occurs and changes only takes effect when server is restarted. It is obviously not intended for development. Check in your %rails_app%/config/environment.rb and see if "ENV[''RAILS_ENV'']" is set to "production", if so, comment that line out and restart the server and you should be good. :) It can be set in other places too though. Hope that helps, Mathias. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2006-Nov-20 21:51 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
> Well actually now I''m at the point where I have to restart the server > whenever I need to update the model... it''s getting annoying :(Are you running in production? If so, switch to development and you''re models should get reloaded on every page request. If it''s a class (say in lib) put "include Reloadable" in it to have it pick up changes all the time... What you are seeing is not the norm. -philip --~--~---------~--~----~------------~-------~--~----~ 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.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2006-Nov-20 21:56 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
Hi All, thanks for the replies! OK I''ve checked, I''m running in DEV mode, not production or anything. It''s not in a lib either. I really don''t know what it could be... here''s the code for the class: class Cart attr_reader :items attr_reader :total_price def initialize @items = [] @total_price = 0.0 end def add_product(product) item = @items.find {|i| i.product_id == product.id} if item item.quantity += 1 else item = LineItem.for_product(product) @items << item end @total_price += product.price end def empty! @items = [] @total_price = 0.0 end end ... as you can see it''s just ''baby'' code - nothing special there. --~--~---------~--~----~------------~-------~--~----~ 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.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2006-Nov-20 21:57 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
I should have added, I can add or edit any method in there - only a server restart makes it take the changes into account. I don''t have that issue with my other class, just that one. --~--~---------~--~----~------------~-------~--~----~ 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.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2006-Nov-20 22:15 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
Problem solved!!! My problem was that Cart was the only object kept... in the session hash. So there you have it, adding: model :cart .. to the application controller solved the problem. Pfweeew! Thank you all for your help! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2006-Nov-20 22:18 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
> Hi All, thanks for the replies! > OK I''ve checked, I''m running in DEV mode, not production or anything. > It''s not in a lib either. > > I really don''t know what it could be... here''s the code for the class: > > class CartRight here add... include Reloadable> attr_reader :items > attr_reader :total_price > > def initialize > @items = [] > @total_price = 0.0 > end > > def add_product(product) > item = @items.find {|i| i.product_id == product.id} > if item > item.quantity += 1 > else > item = LineItem.for_product(product) > @items << item > end > @total_price += product.price > end > > def empty! > @items = [] > @total_price = 0.0 > end > > end > > > ... as you can see it''s just ''baby'' code - nothing special there. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jon Garvin
2006-Nov-20 23:49 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
Sounds like you have your environment (RAILS_ENV) set to ''production''. If so, restarting the webservice (i.e. webrick) will clear the cache out. Better yet, do development with your environment set to ''development''. Then restarting the service won''t be necessary. steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org wrote:> Hi, so basically I''m starting with Rails (moving from Coldfusion/Java). > I''m following the Agile development with rails book, and I have this > method in my model, called ''add_to_cart'', called from the controller. > > Now I was modifying this method, reloaded the page, and noticed my > changed were not being taken into account. I tried clearing the browser > cache, nothing. I tried adding debug message in the method body, > nothing. I tried DELETING THE WHOLE METHOD - nothing - it was still > functionning as if the method was still there. > > In CF it''s called ''bytecode templates'' and they can be easily cleared > when CF chokes on them. I was wondering if there is such a think in > rails - or even better, a way to prevent rails from caching the model > at all when in ''development'' mode. > > TIA! > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Alex Wayne
2006-Nov-21 00:14 UTC
Re: Rails caching the model - is there a way to disable it o
steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org wrote:> Problem solved!!! My problem was that Cart was the only object kept... > in the session hash. So there you have it, adding: > > model :cart > > .. to the application controller solved the problem. Pfweeew! > > Thank you all for your help!The reason this happens is that Rails wil lonly auto-reload models that inherit form ActiveRecord. Your cart is an abstract table-less model and doesn''t get flagged by Rails to be reloaded. Adding include Reloadable marks the class as any ActiveRecord model would be marked for reloading. Also, in edge rails you wont need Reloadable anymore, it should just happen on its own. -- 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 -~----------~----~----~----~------~----~------~--~---
blakeage
2006-Nov-29 23:07 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
I''m having this problem (start webrick, change model, call new model function > gives error "NoMethod..."). I''ve tried pretty much everything. I''m running Rails 1.1.6 on OS X, Webrick. In my "environments.rb" file I have ENV[''RAILS_ENV''] == "development", in my "environments/development.rb" file I have config.cache_classes = false. I''ve also tried lighttpd, and in lighttpd.conf i have "bin-environment" => ( "RAILS_ENV" => "development" ). I can''t imagine telling Rails anymore that I want to run it in development mode, but it still won''t let me access new model methods without server restart. The only way around this seems to be to put require "Reloadable" in every model class. What am i doing wrong? Brian Hogan wrote:> By default, in development mode, your models will always reload on every > request. It sounds like your environment is not set up quite right. I''d like > to hear more about your enviornment... OS, ruby version, whether you''re > using WEBrick or Apache, and what version of the Agile book you''re using. > > > > On 11/20/06, steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org <steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > > > > > Well actually now I''m at the point where I have to restart the server > > whenever I need to update the model... it''s getting annoying :( > > > > > > > > > > > ------=_Part_87338_9584206.1164058596979 > Content-Type: text/html; charset=ISO-8859-1 > X-Google-AttachSize: 879 > > By default, in development mode, your models will always reload on every request. It sounds like your environment is not set up quite right. I''d like to hear more about your enviornment... OS, ruby version, whether you''re using WEBrick or Apache, and what version of the Agile book you''re using. > <br><br><br><br><div><span class="gmail_quote">On 11/20/06, <b class="gmail_sendername"><a href="mailto:steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org">steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org</a></b> <<a href="mailto:steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org">steve.dogers-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org > </a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>Well actually now I''m at the point where I have to restart the server > <br>whenever I need to update the model... it''s getting annoying :(<br><br><br><br><br></blockquote></div><br> > > ------=_Part_87338_9584206.1164058596979----~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Justin Forder
2006-Dec-02 13:39 UTC
Re: Rails caching the model - is there a way to disable it or clear the cache code?
blakeage wrote:> In my > "environments.rb" file I have ENV[''RAILS_ENV''] == "development"If it wasn''t a typo, ''=='' should be ''='' regards Justin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---