I have application, quite big on Rails 5.0.7.2 and Ruby 2.6. But for sometime local development is real pain. When I change one file and try to reload endpoint which serves only JSON response it took almost a minute to get response. I noticed that all controllers under app/controllers and subdirectories are getting loaded once again, like in the first request after booting the app. Serving responses without code changes is fast, only after changing something in code it took long time on first reload.
My config/environments/development.rb file looks like:
Webapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Allow to see previews on development.
config.action_mailer.show_previews = true
config.action_mailer.preview_path = Rails.root.join('spec', 'mailers', 'previews')
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found).
config.i18n.fallbacks = true
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = false
# Generate digests for assets URLs.
config.assets.digest = true
# Fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# caching actions and page fragments
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
I have already tried EventedFileUpdateChecker, but it didn't change anything.
Most of the controllers I have under app/controllers/api directory in Api module.
I am developing on OSX.
It was not caused by the framework configuration itself. All my issues disappeared when I removed gems like better_errors, meta_request and caller_binding from my Gemfile.
Related
I have the following in my config routes:
...
scope module: :public do
...
scope module: :doctor do
get 'vets/new', to: 'vets#new'
...
end
end
So, the nesting is: public -> doctor -> vets.
By accident, I put vets controller into a public folder (app/controllers/public/vets_controller.rb), wrapped it into Public module. And also put an appropriate view: app/views/public/vets/new.html.slim.
This stuff is working correctly on my local machine, but after the deployment process, I get 404 error.
How can I turn this check on in development mode? I need to know about this type of issues on the development stage.
Why do you think it even works on my local machine?
All the documentation that include scope module: "etc" only ever use 1 level of nesting.
Using 2 levels of scope nesting wasn't how it was intended to be used. It's a bug that Rails doesn't notice these errors in development.
To get the errors that you want, change some of the configuration options in your development.rb file. Notice how they are different from your production.rb file.
# config/environments/development.rb
Rails.application.configure do
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# more code
end
To
# config/environments/production.rb
Rails.application.configure do
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot.
# This eager loads most of Rails and your application in memory,
# allowing both threaded web servers and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# more code
end
I've install spree gem and tried to add i18n gem and get the following error:
I'd like to know what is wrong:
My development.rb file :
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
Raises error for missing translations
config.action_view.raise_on_missing_translations = true
end
How do I enable debug info?
config.consider_all_requests_local = true should make you see the error messages.
It looks like you are missing a # before Raises error for missing translations in your configuration.
Are you rescuing the errors somewhere ? Perhaps you have a rescue_from in your application controller? Did you remember to restart your server after changeing the configuration?
Also, I can really recommend the better_errors gem.
How can I fix this problem. Please teach me how to solve this....
First, I had tried to use page cache on my web app. But, it doesn't run well. That was not so good. So, I updated to get rid of page cache. After that, my app's view page that had page cache could not be updated.
below is a my config/environment/development.rb
KaguShop::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
#caching for objects
#config.cache_store = :mem_cache_store
end
And, after I edited my cache setting, I tried this command.
※and of course, I reopen the browser.
rails console
Rails.cache.clear
try ctrl+shift+delete on browser to clear cache.
To perform caching config.action_controller.perform_caching should be set to true
before update you must do something like expire_page :action => action_name
Ex:
def update
expire_page :action => profile
...........
end
I gathered information about caching at 2 places other day. Check them here and here
OMG....
This is the answer of this question.
I didnt know this rails's structure...
After removing caches_page cached sites are still not updated
Every time I change anything in controller's or in models, I have to restart the server for it to take effect.But that wasn't always the case, it used to work normally before, when I changed anything, but i don't know what happened now ?
My Rails version is 3.2.11
In my development environment file i have set config.cache_classes = false.
Please help..
My development.rb file is as follows
Testapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
I have got the answer..
After adding following line in my config/environments/development.rb file my issue has been resolved.
config.reload_classes_only_on_change = false
start your server using below command in console
rails server -e development
if not started then give your rails version and which sever you use for run rails application.
more Configuration
modify your config/environments/development.rb file to:
config.serve_static_assets = false
An additional situation where this can come up is in a virtualized environment where the files are being edited on the host operating system, and the guest operating system's file event manager doesn't generate events for file changes.
A solution for this situation is to comment out the following line in config/environments/development.rb:
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
Thus giving:
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
This forces rails to actually check file modification times instead of expecting to get filesystem events.
There is a good note for VirtualBox users, posted as comment by user Ninjaxor:
For Vagrant/ virtual box users, there's a bug where if the host clock
and guest clock are out of sync, it borks rails' reloader.
https://github.com/rails/rails/issues/16678
The file Vagrantfile you find in a directory like this:
.../ruby/gems/sass-3.4.22/vendor/listen
There you have to add this:
# Sync time every 5 seconds so code reloads properly
config.vm.provider :virtualbox do |v|
v.customize ["guestproperty", "set", :id, "--timesync-threshold", 5000]
end
Thanks to user axsuul on GitHub!
I noticed that setting
config.cache_classes = false
is what did the trick for me.
Normally, any changes I make to .js.coffee files in my Rails 3.2.0 app in development mode take effect when I refresh the page. All of a sudden, this is not happening. If I do rake assets:precompile, then the changes are shown, but then if I do rake assets:clean they go back to not being shown. What is causing this?
Edit: Restarting the server makes the changes show. Why isn't this happening automatically as before?
Edit: Here is my development.rb
Myapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.log_level = :warn
end
I'm quite new in Rails (well... I only learn programming for <3 months
I would guess:
You or some installation change your config in config/application.rb
Can you check in the file:
Is config.assets.initialize_on_precompile being false?
Change to true and try again.
Also check config.assets.compile. Is it true?
You might change the default value in Rails 3.2. So, I suggest you to think why the change(s) happens.