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.
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.
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.
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.
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.
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?