This is probably very simple but I can't figure out why I get no error pages.
First off, I'm using Heroku for hosting, so it's definitely in production mode.
If I set the line "config.action_controller.consider_all_requests_local" set to true, I get a detailed error message but otherwise, I get a completely 100% blank screen. If I view the source, also blank.
All my 404,422,500.html files are in public and I haven't touched them.
And they seem to work on my local machine if I start in production mode there. So it must have to do with Heroku? Any ideas?
The logs tell me nothing useful.
Below is the details of the production.rb file
config.cache_classes = true
#ActionMailer::Base.delivery_method = :sendmail
Paperclip.options[:command_path] = "/usr/bin/"
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.action_view.cache_template_loading = true
I don't think Heroku uses the .html files like Passenger or Mongrel do. You may need to catch and handle your own exceptions through two basic mechanisms:
Create an exception handler with rescue_from in your ApplicationController for anything that might explode, both specifically and up to and including Object.
Create a default route to catch anything that isn't otherwise routed.
If you bust out of your routing table, or trigger a "500" error, it's because of exceptions. These need to be handled or you'll get a blank screen unless the web server is configured otherwise.
Apache can be configured to do this with the ErrorDocument directive.
Related
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.
Title says it all.
Note that this is not about a change in the model or initializers.
I can delete an instance variable in the controller (say, #user) and then reload a view and it will work - until I restart the server, in which case it will complain about the variable being nil.
I was working normally and then switched to work on a totally different set of controllers and views and now it's happening for no reason whatsoever.
The app is in a development environment.
development.rb contents:
Dashboard::Application.configure do
config.cache_classes = false
config.whiny_nils = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.action_dispatch.best_standards_support = :builtin
config.assets.compress = false
config.assets.debug = true
end
How can I find out how it's happening and how do I fix it?
Edit:
**It's likely related, but I can't seem to use any paths that exist when running 'rake routes' in a partial, such as dashboards_path**
Plot twist:
Adding
config.reload_classes_only_on_change = false
to development.rb seemed to have ameliorated the issue. I still would like to know why it happened, why it happened out of the blue and why it happened to one controller but not the other.
Rails uses the autoload paths config to determine what files to auto load, and reload:
module YourApp
class Application < Rails::Application
config.autoload_paths += %W( #{config.root}/lib #{config.root}/lib/**/ #{config.root}/app/traits )
...
end
end
As you can see I have added a custom directory, the app/traits directory, where I store some modules that define shared behavior.
If the controller you started working on is in a subdirectory that is not watched by rails or has permissions that stop rails from attaching a file system changed event you get this problem.
The reason that config.reload_classes_only_on_change = false "solves" the problem is that the entire app is reloaded on every request instead of relying on detecting changes to files.
Most likely the controller is not in the watched files list and thats why rails is not reloading it on change. The exact reason why it's not on the list might vary and I need more details about the folder structure and config of the app before I can give a good answer there...
I'm trying to work out why when working on a 404 page on a rails app I'm working, the only way to see changes I've made to the html on the page is to physically restart the webserver with a ctrl-C followed by a call to script/server.
As far as I can tell, I can't see anything particularly wrong with the development.rb config file here:
# Settings specified here will take precedence over those in config/environment.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 webserver 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.action_controller.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = false
# add rack bug
# config.middleware.use "Rack::Bug"
# this disables the caching for comatose, not the rest of the app
# config.disable_caching = true
config.action_mailer.default_url_options = { :host => "localhost:3000" }
config.gem "thoughtbot-factory_girl",
:lib => "factory_girl",
:source => "http://gems.github.com"
This alone won't display the error pages locally, so in application_controller.rb I've aliased rescue_action_locally to the rescue_action_in_public method, to stop me seeing the stacktrace:
# this method allows you to test 404 and 500 pages locally
alias_method :rescue_action_locally, :rescue_action_in_public
This here shows me the error page once, but then caches it so that future reloads show the state of the html file when the server was loaded.
The log output doesn't show me any weird caching behaviour - it's getting a request for a non-existent resource, not finding anything, then rendering the html page as required:
chrisadams#r220-101-174-100 ~/RailsApps/annoying_app > script/server --debugger
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
=> Debugger enabled
=> Call with -d to detach
=> Ctrl-C to shutdown server
SQL (0.2ms) SET SQL_AUTO_IS_NULL=0
Processing ApplicationController#index (for 127.0.0.1 at 2009-12-28 19:23:27) [GET]
ActionController::RoutingError (No route matches "/non-existent-resource" with {:method=>:get}):
Rendering /Users/chrisadams/RailsApps/annoying_app/public/404.html (404 Not Found)
The 404.html is totally static, without any ERB in there at all, and this static html page is what isn't changing between page refreshes.
What am I doing wrong here? This is driving me crazy!
I've noticed that not everything is reloaded on every request, even in development mode. Is your 404.html page completely static, or are you running it through ERB or something?
rescue_from is also becoming the generally preferred means of doing this nowadays.
I'm not sure if this might help you, but one time I accidentally uncommented the lines ENV['RAILS_ENV'] ||= 'production' in environment.rb and my app started in production mode even when I didn't specify the environment.
Could that be the case for you?
What is the purpose of this Rails config setting...
config.action_controller.consider_all_requests_local = true
It's set to true by default in config/environments/development.rb.
Thanks,
Ethan
Non-local requests result in user-friendly error pages. Local requests, assumed to come from developers, see a more useful error message that includes line numbers and a backtrace. consider_all_requests_local allows your app to display these developer-friendly messages even when the machine making the request is remote.
At development level we set:
consider_all_requests_local set = true
because developer needs to take a look at full error showing layout/view as you can see in the image below.
But at production level, we don't need to show our internal coding bug so we set false:
config.consider_all_requests_local = false