Rails not reloading classes - ruby-on-rails

I have a rails app in development mode that is not reloading any model/controller classes upon modifying the files unless the dev server is reset. The same exact project used to reload the files fine but without any apparent changes it is no longer working.
I have config.cache_classes = false set in my development.rb file. I have also confirmed that I am running in development mode. I have went as far as printing the cache_classes variable out to the screen with the server running to confirm it is false, which it is.
I am not running in threadsafe mode, I read this can mess the the cache_classes setting.
I have also confirmed that the timestamps on the files are being updated when I save them. I am running Rails 3.2.13. I have the same result when using either webrick or pow. What could be causing the classes to not being reloaded?

Related

Low-level caching doesn't work in development, even after running rails dev:cache

I'm trying to get Rails low-level caching working in my local development environment. I ran rails dev:cache, which created the tmp/caching-dev.txt file as expected. And my config/environments/develpoment.rb file contains the code that checks for the existence of that file and turns on caching if it's present. But the cache isn't being used when I run my app.
Even when I modify my development.rb file directly to set config.cache_store = :memory_store regardless of whether tmp/caching-dev.txt is present, low-level caching still does not work!
What else am I missing to get caching working in development?

Avoid restart in Rails production environment to see changes saved

Sometimes I have to start our application server with the production environment. It always has surprised me that changes saved on development are instantly loaded, while those made on production environment aren't.
What is the reason behind it? How can I change it so anything saved is "seen" on the server?
Thanks.
It's on purpose. Reloading the code between each request requires a reasonable amount of time and resources, therefore it's not advisable for a production environment.
You can change the setting from the production.rb environment configuration
# Code is not reloaded between requests.
config.cache_classes = true
Change it to false.
I suggest you to not make the change permanent on production, rather just toggle the value temporarily if you need to quick check something.

Can I change config.cache_classes programatically in Rails 3?

I have some iPhone client tests that run against my development rails server. The whole suite runs an order of magnitude faster if I turn on class caching in the Rails config. On the other hand, that slows down development when I'm not actually running the tests.
I want the test suite to hit an action at the beginning to turn on class caching and another action at the end to turn class caching off again.
Is this even possible? If so, how?
Not without some serious hacking. Rails goes to quite a lot of trouble to make sure your files are reloaded on every request (when cache_classes=false). The value of the cache_classes configuration variable is used by initializers in several places not the least of which being:
using require to load ruby files when cache_classes is true (meaning they are no longer reloadable)
setting up dispatcher callbacks to reaload the application on every request when cache_classes is false
You do have access to the value of the cache_classes variable, and you can even change it if you like:
Rails.configuration.cache_classes = true
But, this will have no effect on the running rails instance as the initializers where that value is used only run once when the rails app starts up.
What this means is this, unless you're prepared to invest some serious time and hacking effort you can't really avoid a restart of your server. So, what you need to look at is controlling this restart process via your test suite.
For example you can try to restart rails from within rails. This would allow you to define an action that your test suite can hit right before it begins executing (to restart the server in the right mode), and another action which the server can hit after all tests have finished, to restart everything with cache_classes set to what it used to be. You would control the value of cache classes via an environment variable like this post suggests.
It would still require a bit of work to set all of this up and get it to hang together, but this is probably your best bet if you want an 'auto-magical' solution.
I don't think doing what you suggest will work.
But I suggest you may be looking for the wrong solution.
If what you want is to access your development database from your iphone testing,
then why not add a new environment.
Add a new file config/environments/iphone_dev.rb
require File.dirname(__FILE__)+"/development.rb"
config.cache_classes = true
And in your database.yml (or mongoid.yml or whatever)
iphone_dev:
host: localhost
database: my_app_development
There is no reason the database cant be the same
Now just run rails server -eiphone_dev -p3001
You should have a server, almost the same as your dev server,
but running on a different port, with caching enabled.

Server does not show recent changes

I'm developing a Ruby on Rails project related to semantic technology, and I'm making something basic that allow the uploading of files and searching in those files.
So far it's all working out ok, but I have noticed that when I make changes to my code files or haml files, I don't see those changes on the webserver. Only after either rebooting the server or mashing the F5 button like crazy, the changes come through. And even that is not guaranteed.
The server is running on a local, virtual, ubuntu system. This is an Apache2 webserver configured with Passenger. The website is visibile, it's just not always the latest changes.
Anyone have an idea what might be causing this, or how I can fix this?
In your config/environments/environment_name.rb file it's likely that you have these lines:
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
Which you can switch to have the behavior you want.
If you don't want to change these then you can just touch tmp/restart, which will push the changes through (it's quicker and more graceful then restarting the web server)
To change the environment passenger runs in add the following line to your vhost:
RailsEnv development

difference between three development modes in rails

What are the difference between three modes in rails like:-
In development mode, Rails reloads models each time a browser sends in a request,
so the model will always reflect the current database schema.
EDIT
I was asking about the other differences. I mentioned one i was looking for other list of differences...!!
It comes down to performance and stability. In production mode, model are cached in memory, meaning that once they have been read once, the files don't have to be read again, bringing an obvious speed benefit. This means that if you were to alter the ruby file (eg app/models/page.rb) where a model is defined, this change would not be picked up until the next reload.
By default, the following line is found in config/environments/production.rb:
config.cache_classes = true
The assumption is that when you're in production mode, you won't be changing your code other than via a release or deployment. If you want to clear the cache, you need to restart the application.
The development environment will reload your models each time it receives a request. This is controlled by the following default line in config/environments/development.rb:
config.cache_classes = false
In terms of the 'third' mode, I presume you mean test mode. This also caches models by default (see config/environments/test.rb), again with the assumption that you won't be altering your codebase mid-way through a test run.
Btw, it's not just models - I'm pretty sure that this setting encompasses any classes found within the 'app' directory. In addition, you will find that, even in development mode, classes located elsewhere in the application (eg 'lib') can not be changed without restarting the application.
The behavior of the three modes is configured in:
rails_app/config/environments/[production|development|test].rb
So, it depends on your configuration how the three modes are different.

Resources