Hello, people! I have a problem. I googled, asked for help on IRC. I can''t find an answer. Suppose I have model Cart (from "Agile Web Development with Rails"). I added call to logger.warn("Some warning") to one of it''s methods. It fails with NameError, because ''logger'' is unknown to model. undefined local variable or method `logger'' for #<Cart:0x36b3bd8 @items=[], @total_price=0.0> Then I deleted offending line. Hit Refresh. Same error. Cleared session cookies. Tried again. Same error. Looks like model is cached. Restarted WebRick. Now it''s OK until next syntax error in model. I''m running rails 1.0.0, ruby 1.8.2 on windows xp sp2. I use webrick in development mode. Why Rails behaves like that? What can I do to prevent this kind of caching? -- olegf
Oleg Frolov wrote:> Hello, people! > > I have a problem. I googled, asked for help on IRC. I can''t find an > answer. Suppose I have model Cart (from "Agile Web Development with > Rails"). I added call to logger.warn("Some warning") to one of it''s > methods. It fails with NameError, because ''logger'' is unknown to > model. > > undefined local variable or method `logger'' for #<Cart:0x36b3bd8 > @items=[], @total_price=0.0> > > Then I deleted offending line. Hit Refresh. Same error. Cleared > session cookies. Tried again. Same error. Looks like model is cached. > Restarted WebRick. Now it''s OK until next syntax error in model. > > I''m running rails 1.0.0, ruby 1.8.2 on windows xp sp2. I use webrick > in development mode. > > Why Rails behaves like that? What can I do to prevent this kind of > caching?Yep, that exactly what rails did. You have to restart Webrick every time that you modify model or helper. However, you might be about to control this behavior to some extend. Check the <application directory>/config/environment.rb. The RAILS_ENV is control this behavior, say in production mode, Webrick always cached the models, controllers, and the helpers. If you modifly one of those files, you have to restart the server. In the development mode, it''s suppose "not to" cache it. I develop using Apache in linux, and I have no problem with caching. I just modifly the code, and refresh the page. However, when I try with Webrick, I need to restart the server anyway, even in development mode. The only drawback of using Apache and development mode is that it''s a bit slower. If most of the time you are modifly views, you should not have any problem them. :) Have fun Tom
Thanks for your tip! Today I have found errata for my version of book. David said, it is bug in Rails. There are two workarounds. You can either require_dependency "cart" to the top of store_controller.rb. Or include the "model :cart" line in application_controller.rb. http://books.pragprog.com/titles/rails/errata Problem solved. olegf On 12/26/05, Anocha Yimsiriwattana <tawtao-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oleg Frolov wrote: > > > Hello, people! > > > > I have a problem. I googled, asked for help on IRC. I can''t find an > > answer. Suppose I have model Cart (from "Agile Web Development with > > Rails"). I added call to logger.warn("Some warning") to one of it''s > > methods. It fails with NameError, because ''logger'' is unknown to > > model. > > > > undefined local variable or method `logger'' for #<Cart:0x36b3bd8 > > @items=[], @total_price=0.0> > > > > Then I deleted offending line. Hit Refresh. Same error. Cleared > > session cookies. Tried again. Same error. Looks like model is cached. > > Restarted WebRick. Now it''s OK until next syntax error in model. > > > > I''m running rails 1.0.0, ruby 1.8.2 on windows xp sp2. I use webrick > > in development mode. > > > > Why Rails behaves like that? What can I do to prevent this kind of > > caching? > Yep, that exactly what rails did. You have to restart Webrick every time > that you modify model or helper. > > However, you might be about to control this behavior to some extend. Check > the <application directory>/config/environment.rb. The RAILS_ENV is > control this behavior, say in production mode, Webrick always cached the > models, controllers, and the helpers. If you modifly one of those files, > you have to restart the server. > > In the development mode, it''s suppose "not to" cache it. I develop using > Apache in linux, and I have no problem with caching. I just modifly the > code, and refresh the page. However, when I try with Webrick, I need to > restart the server anyway, even in development mode. > > The only drawback of using Apache and development mode is that it''s a bit > slower. If most of the time you are modifly views, you should not have any > problem them. :) > > Have fun > Tom > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >