What is Config.Eager_load and how do I fix it? - ruby-on-rails

I've been trying to run a rails db migrate command, and its worked on many apps with the same setup as this one, but for whatever reason I am getting the following error:
config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
* development - set it to false
* test - set it to false (unless you use a tool that preloads your test environment)
* production - set it to true
But here's the thing. All of those are set correctly. I've even tried setting them incorrectly running it, and setting them correct again. I've restarted my computer, my app. Everything. I can't find a good explanation of what config.eagar_load even really is either. What is this thing? Why is it messing up my app? How do I even troubleshoot it?
Answer in part: I was using rails db migrate and should have been using rails db:migrate so that fixed the problem, but I would still like to know what config.eager_load is, and what it does.

I recommend you this great post.

Related

Rails files not updating unless server restart

I am working on a Ruby on Rails project, and each time I want my changes to take effect (views, controllers, anything really) I am forced to close the server and restart it. I tried to find a solution to this but Googling it didn't help me at all. Does anyone know how to fix this issue?
Go to config/environments/development.rb and add these two configs or change them to false
config.cache_classes = false
config.eager_load = false

clearing rails cache dynamically

I am working on rails application , in which i am using ruby 1.9.2 and rails 3.0.8. My application is running quite fine in development environment, which includes creating tables from the application and accessing them.
But when i start my application in production environment in which caching is enabled, every thing is working fine , i am not able to access the table which i am creating using my application. I am able to access these tables after restarting the server, which is a pain.
I am searching for a way where i can clear the cache whenever new table get created, can you please help me to clear the cache dynamically.
Thanks
Naveen Kumar Madipally
The one workaround would be to do this in your environments/production.rb (which is not at all recommended on production)
config.cache_classes = false
this will decrease your performance in production but what you can do is fo to production.rb file and check the blow lines
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
i guess it will solve your problem
There are abstractions for that in ActionDispatch::Reloader : it's what's used in development environment to reload classes.
So basically, you would need to run :
ActionDispatch::Reloader.cleanup!
ActionDispatch::Reloader.prepare!
I'm not sure it would be such a good idea, though, as you can't expect which code (yours or from gems) does things that are supposed to happen only once.
Couldn't you use STI rather than dynamicly creating tables ?

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.

Rails 3 development environment keeps caching, even without caching on?

i have a rails 3 app in dev mode that won't load any changes i make when its running webrick. i triple checked the settings for my development.rb and made sure i am running in development mode.
config.cache_classes = false
config.action_controller.perform_caching = false
i also checked my tmp directory to make sure the cache folder is empty - i have yet to do any caching on the site and have never turned on caching. im guessing its a loading problem with the files.
also i was running on webrick then installed mongrel and the problem still persists.
im guessing ive run into a config problem, bc i dont see anyone else posting such a prob. anything else im missing?
EDIT: it looks like my view helpers aren't auto loadable - aren't helpers by default supposed to be reloadable in rails 3?
I've had a similar experience, but I don't believe it was with an actual helper class, it was with anything I wrote under the lib/ directory. If you've had to use a require 'some_class' statement, then you should switch it to:
require_dependency 'some_class'
Worked like a charm for me.
I had the same problem and here is the simple solution.
In your config/environments/development.rb set following settings:
config.action_controller.perform_caching = false
config.perform_caching = false
config.cache_store = :null_store
I know this is an old question, but for anyone coming here with a similar issue, make sure you didn't accidentally move production.rb from config/environments/ to config/initializers/ like I did. That will make Rails read in the production.rb file and override your development settings. Whoops.
Had the same issue, it was caused by rails-dev-tweaks gem which is, if you used default configuration from README, disabling stack reload upon AJAX requests.
I'm using Rails 4, and my cache call was in a helper using Rails.cache.fetch.
After googling a bit, I found out this issue (https://github.com/rails/rails/issues/20733), where a PR was merged into rails 5 documentation to make clear that '
Changing the value of config.action_controller.perform_caching will
only have an effect on the caching provided by the Action Controller
component. For instance, it will not impact low-level caching, that we
address below.
', being 'low-level-caching' the Rails.cache.fetch.
It's on the docs now: http://guides.rubyonrails.org/caching_with_rails.html

Cucumber test not deleting data

I have a project with several features in cucumber both plain and selenium are failing indicating problems when trying to create a user because of the email uniqness validation (so the records are not being deleted and every background on the feature is failing)
I get a warning like this "WARNING: You have set Rails' config.cache_classes to false (most likely in config/environments/cucumber.rb). This setting is known to break Cucumber's use_transactional_fixtures method. Set config.cache_classes to true if you want to use transactional fixtures. For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165."
Weird enough all my enviroments have the session_cache set to true (just development hast it on false but I also tried setting it to true and run it)
Also the same project is working on other computers I tried uninstaling ruby and all the gems from rvm and reinstall but I still get the same error
Any ideas what else i could try to solve this on my mac? also database cleaning strategy is set to fixtures
I appreciate your time
I would try using a hook to clear out the data.
https://github.com/cucumber/cucumber/wiki/Hooks
A before hook that will do a .destroy on all records to ensure a clean start may be a good bet. It feels hacky to me, but may help you further diagnose the failure.

Resources