I have started to learn Rails today. I am following an online tutorial. I am getting an error. In the tutorial whenever there is an error, the reason for the error is displayed in the browser. But I just get this message:
We're sorry, but something went wrong. If you are the application owner check the logs for more information.
How can I make Rails to show display the actual error like how Django displays the error when debug = True in settings.py file?
development.rb
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
log
/usr/lib/ruby/vendor_ruby/rails/app_rails_loader.rb:39: warning: Insecure world writable dir /usr/lib/jvm/java-8-openjdk-amd64/bin in PATH, mode 040777
Array values in the parameter to `Gem.paths=` are deprecated.
Please use a String or nil.
An Array ({"GEM_PATH"=>["/var/lib/gems/2.5.0", "/home/laxman/.gem/ruby/2.5.0", "/usr/lib/x86_64-linux-gnu/rubygems-integration/2.5.0", "/usr/share/rubygems-integration/2.5.0", "/usr/share/rubygems-integration/all"]}) was passed in from bin/rails:3:in `load'
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
/usr/lib/ruby/vendor_ruby/sprockets/digest_utils.rb:47: warning: constant ::Fixnum is deprecated
/usr/lib/ruby/vendor_ruby/sprockets/digest_utils.rb:51: warning: constant ::Bignum is deprecated
/usr/lib/ruby/vendor_ruby/sprockets/processor_utils.rb:110: warning: constant ::Fixnum is deprecated
/usr/lib/ruby/vendor_ruby/sprockets/processor_utils.rb:111: warning: constant ::Bignum is deprecated
=> Booting WEBrick
=> Rails 4.2.10 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2019-04-27 16:46:06] INFO WEBrick 1.4.2
[2019-04-27 16:46:06] INFO ruby 2.5.1 (2018-03-29) [x86_64-linux-gnu]
[2019-04-27 16:46:06] INFO WEBrick::HTTPServer#start: pid=2467 port=3000
Started GET "/" for 127.0.0.1 at 2019-04-27 16:46:10 +0530
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
config.ru
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Proj
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end
After reviewing the full application you posted, I was able to reproduce the problem.
This issue has been reported before, in other StackOverflow posts, but I'll repeat it here:
You need to update the web-console gem to version 3.0+; in particular due to this bug fix for running the rails server in a VM/container behind a proxy.
In other words, you need to update this line in your Gemfile to:
gem 'web-console', '~> 3.0'
and then run bundle install.
On a related note, you seem to be using many outdated software versions in your project (e.g. rails version 4.2). Issues like this can usually be mitigated by keeping your dependencies up-to-date.
Related
There are similar posts like this, this, and this, but none answer the question.
How does all.js get compiled in production for Rails 3.2.12? As illustrated below by the production.rb file, compiling assets is disabled so it's unclear how all.js gets generated in the first place.
Running rake assets:precompile generates the following error:
rake aborted! Don't know how to build task 'assets:precompile' (See
the list of available tasks with rake --tasks)
The root issue is how to update all.js to reflect the newest code in application.js. Restarting the server hasn't helped, so what triggers all.js to get recompiled?
Test::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"
# For nginx:
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# If you have no front-end server that supports something like X-Sendfile,
# just comment this out and Rails will serve the files
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Disable Rails's static asset server
# In production, Apache or nginx will already do this
config.serve_static_assets = false
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# 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
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to Rails.root.join("public/assets")
# config.assets.manifest = YOUR_PATH
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
end
We finally were able to refresh all.js with the newest changes from application.js using these (suboptimal) steps:
Discovered the installed Ruby was incompatible with Rails 3.2.12, so downgraded to Ruby 2.1.2. This fixed the rake assets:precompile error.
Ran the following commands, some of which are likely superfluous but there was no time to isolate the minimal number of steps needed:
bundle exec rake assets:clean
bundle exec rake assets:precompile
bundle exec rake assets:precompile RAILS_ENV=production
rake assets:precompile --trace
rake assets:precompile RAILS_ENV=production
rm all.js
The regenerated all.js magically appeared after the rm all.js step, but in case this doesn't work for others, please remember to back up all.js first!
I would like run a gitlab ruby on rails project.
After cloning I would like to build up the environment but there is permission problems. config/environments/development.rb get chmod +x then I use config/environments/development.rb command:
config/environments/development.rb
config/environments/development.rb: line 1: Rails.application.configure: command not found
config/environments/development.rb: line 7: config.cache_classes: command not found
config/environments/development.rb: line 10: config.eager_load: command not found
config/environments/development.rb: line 13: config.consider_all_requests_local: command not found
config/environments/development.rb: line 14: config.action_controller.perform_caching: command not found
config/environments/development.rb: line 17: config.action_mailer.raise_delivery_errors: command not found
config/environments/development.rb: line 20: config.active_support.deprecation: command not found
config/environments/development.rb: line 23: config.active_record.migration_error: command not found
config/environments/development.rb: line 28: config.assets.debug: command not found
config/environments/development.rb: line 32: config.assets.digest: command not found
config/environments/development.rb: line 37: config.assets.raise_runtime_errors: command not found
config/environments/development.rb: line 41: end: command not found
And this is the development.rb
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
Ruby 2.3.0
Rails 4.2.6
bundle install run successfully
The project use 2.3.0 ruby
You don't run the environment file, that is for configuration purposes only.
You need to run the web server, which serves GitLab. Read docs about starting the web server, usually it's bundle exec rails s, but it would depend on the setup.
Why are you trying to run the development.rb. It is only for configuration. Settings specified here will take precedence over those in config/application.rb.
When you do a rails s i.e run your rails server, the file gets executed. The environment.rb requires the application.rb before it initializes the rails app.
If you want to just run your rails app then doing a rails s should be fine
I am pretty much brand new to RoR and such.
I am following a video tutorial to build my own web-based app, and I got to the step:
git push heroku master
When in git bash, it was coming up with an error that claimed it couldn't compile ruby. Now, it says it is launched and deployed, but there is still the same error on the page for my app, http://infinite-mountain-6131.herokuapp.com/
Any ideas?? I can add files if needed.
Requested file(s):
app/config/application.rb from my comment
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# config/application.rb
config.assets.initialize_on_precompile = false
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Myrubyblog
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end
Line 6 that was mentioned in my error is the config.assets.initialize which I put in there with line 5 as suggested to fix my problem.
This is what happens when I run the migrate as suggested (heroku run rake db:migrate)
Running 'rake db:migrate' attached to terminal... up, run.6274
rake aborted!
NameError: undefined local variable or method 'config' for main:Object
/app/config/application.rb:6:in '<top <required>>'
/app/Rakefile:4:in 'require'
/app/Rakefile:4:in '<top <required>'
<See full trace by running task with --trace>
As a rule, there are two types of error you can get when hosting a Rails app on Heroku:
Heroku Error
-
Rails Error
--
Error
The difference between the two is important - rails errors will only occur if your operating environment is actually "running" your Rails application. Heroku errors will occur if your operating environment / Heroku will not load correctly
The problem you have is definitely a Heroku issue - one which is typically created by a lack of db connectivity. The way to fix this issue is to ensure your application has all the necessities to run - most notably the correct db
You'll be best using the following:
$ heroku run rake db:migrate
However, I appreciate this won't be the only issue you'll have
Heroku Deployment
As you've said you're a "beginner" to ROR, let me give you some ideas
Firstly, when you write a question on here, it helps to divulge as much information as possible - typically from the logs, or any other specific error handling mechanism
Secondly, you want to ensure that everything required to get your application running has been achieved. Most notably, when you mention Heroku cannot compile the Ruby application, you'll need to provide information on why this is the case -- there'll probably be a gem conflict (SQLite3) or similar
Thirdly, you need to ensure you have migrated your database. This is the single biggest reason why "Heroku errors" appear - deploying your Rails app doesn't mean the migrations you made locally will persist - you need to ensure you have the db updated as you require, which can be done as follows:
$ heroku run rake db:migrate
I'm new to Ruby and am following the Michael Hartl's tutorial. I'm still on chapter 1.
It says
undefined local variable or method 'first_app' for main:Object (NameError)
which is in my development.rb line 1.
Firstapp::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
# 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
I followed other questions on StackOverflow with no solution. Some of them require to changed my app name from
Rails.application.configure do
to
First_app::Application.configure do
which didn't resolve anything. Oh and if it helps, I'm using Windows.
When you ran the rails new command it should have properly set your app's name. I think what happened is you probably ran rails new firstapp instead of rails new first_app. ChangeFirst_app::Application.configure do to FirstApp::Application.configure do. You should also probably do a search in your project for Firstapp or First_App and change those as well.
It had something to do with my Gem file apparently. I didn't edit it this and left it alone, the application ended up compiling without any errors. I think it has something to do with SQLite3 gem that I'm not properly doing something regarding version.
I'm creating a new rails 3.2 project and everything is loading fine except the last modifications I made on css files.
If I do app/assets/stylesheets/application.css change anything on this file, I can't see the changes on the browser until I run the following command at console:
bundle exec rake assets:precompile RAILS_ENV=development
my config/environment/development.rb file.
Sample::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
end
Any help?
The problem was that I'd compiled the assets, so the rails was serving the already compiled version of these files.
In this case, all you have to do is, just delete the already generated files, like application.css and application.css.gz and you well get it working again.
Hope it helps someone.
Running bundle exec rake assets:clean solves the problem. Also if you want to manually delete these files they are present in the app's public folder inside assets.
This is kind of an old thread, but I've found that sometimes a rake assets:clean won't take care of it in Rails 4.2.1. Sometimes, you need to use a stronger verb like clobber: rake assets:clobber