See more errors details rails - ruby-on-rails

How can see more detailed errors in my rails app when I'm developing.
Right now I just get this:
I know that is possible to activate something to see the errors in more detail, but I don't know how to do it.
Any help?
Edit1:
In my development.rb file I have this:
# 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
Edit2:

Check you development.rb to ensure that:
config.consider_all_requests_local = true

Related

Session ID changes when I make a POST request in Rails but only during tests

I'm having a rather odd issue in that POST requests triggered by link_to with method: :post. In the test environment the session_id seems to change. This causes issues such as the current_user object doesn't exist within the action I'm posting too. I've logged out the request and the session info and I can see that the session has changed for the POST action and when I try to use current_user the test fails.
I have other POST requests through forms around the app. And they work fine. It seems to be some Rails magic around the link_to with method: :post and passing the CSRF token.
I'm able to get around this by changing my test.rb to be the same as my development.rb. But I'm sure this isn't a good solution. It's possible it's related to some configuration but it seems like this is the default behavior.
Controller
class RecruitersController < ApplicationController
before_action -> { STDOUT.puts "Request: #{request.method} #{request.fullpath}" }
before_action -> { STDOUT.puts "Session: #{session[:session_id]}" }
...
end
Button that triggers the POST Request
= link_to "<3", recruiter_request_url(id: recruiter.id), method: :post, remote: true
Output in Tests
Request: GET /recruiters/dashboard
Session: ee8c577fdf6d1714c2a837f0890e0294
Request: GET /recruiters/premium
Session: ee8c577fdf6d1714c2a837f0890e0294
Request: POST /recruiters/request_premium_trial/1
Session: 314c6eef0156aa36a469a4f9ea7513a8
Output in Development
Request: GET /recruiters/dashboard
Session: cdb333efb5d62e6ddbb5914c8edd7a92
Request: GET /recruiters/premium
Session: cdb333efb5d62e6ddbb5914c8edd7a92
Request: POST /recruiters/request_premium_trial/1
Session: cdb333efb5d62e6ddbb5914c8edd7a92
The Spec
Simple spec user signs in goes to the dashboard, goes to the premium page and then clicks on the link that makes the POST request.
scenario 'Should be able to make request', js:true do
rsign_in # Function that simulates sign in
click_on 'Premium'
click_on '<3'
assert_text 'Request made' # Fails as we're redirected to sign in page when we try to authenticate the user
end
Test.rb
Rails.application.configure do
# Set log level
config.log_level = :debug
# This means that all URLs need to have 5 parts to them. This is for http://recruiter.127.0.0.1.xip.io:3000
config.action_dispatch.tld_length = 5
# Settings specified here will take precedence over those in config/application.rb.
cache_store = :file_store, "tmp/cache"
# Use a different job queue
config.active_job.queue_adapter = Figaro.env.job_queue.to_sym if Figaro.env.job_queue?
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = true
# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_controller.default_url_options = { host: 'localhost:5000' }
config.action_mailer.default_url_options = { host: 'localhost:5000' }
config.action_mailer.delivery_method = :test
# config.action_mailer.delivery_method = :smtp
# config.action_mailer.smtp_settings = { address: 'localhost', port: '1025' }
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
config.active_record.raise_in_transactional_callbacks = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
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 = true
config.action_mailer.preview_path = "#{Rails.root}/app/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
config.action_mailer.default_url_options = { host: 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: 'localhost', port: '1025' }
config.cache_store = :dalli_store
# Use a different job queue
config.active_job.queue_adapter = Figaro.env.job_queue.to_sym if Figaro.env.job_queue?
# 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
config.after_initialize do
Bullet.enable = false
Bullet.alert = true
Bullet.console = true
Bullet.rails_logger = true
end
end
Seems like the error was coming from this line in my test.rb, was just trying to set the default host on my links to not be example.com. Not sure how this resulted in the bug I was experiencing. But after going through the config and trying to figure out why development.rb was working. This is what I got.
config.action_controller.default_url_options = { host: 'localhost:5000' }
Thanks to everybody who helped me.

How can I speed up Rails development server?

I am working on Rails 4.2 & Angular 1.4.8 as the front-end. This is my development.rb file:
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.raise_runtime_errors = true
config.action_mailer.delivery_method = :letter_opener_web
config.action_mailer.default_url_options = {host: "localhost:3000"}
config.consider_all_requests_local = false
end
I know that by disabling assets.debug I can really speed this up, but I need to have my assets refreshed when I refresh the page. I am doing full stack so I can't precompile assets all the time.
I recently started using guard with guard-rails - do I have any chance ?
I suspect that compiling all assets every time after file changed.
if you require angularjs libs and other libs in to application.js try to create a separate file for libraries and application
See also: Rails 3.1 is very slow in development-mode because of assets, what to do?

Heroku push incomplete

I have a rails app that works perfectly in localhost, but last time I pushed it to Heroku the "About" and "Contact" sections seems like incomplete upload or something, here is the link to the website https://damp-inlet-9409.herokuapp.com, and yes, I re-pushed like 3 times and still the same result
Update:
I think the problem is from development.rb or production.rb, here you got them:
Production.rb
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
Development.rb
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
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.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
end
There are several potentialities with your issue.
Firstly, you're getting a rails error, which means that at the base level (IE Heroku database etc), the app should be working okay.
The main problem for many Heroku apps is that they either don't have a database, which would yield the Heroku "Application Error":
For future reference, this error means that you have an issue with how Heroku is running your app (typically that you don't have a db or something).
Since you have a rails error, it means that the problem is likely an undeclared variable, or missing conditional login etc.
--
To fix the issue, you need to check the Heroku logs:
This will give you a specific readout of the problem that's preventing the app from running. You'll then either be better placed to give us the details of said error, or fix the problem yourself.

Assets compiling on fly (Rails with compass gem)

I am trying to change my styles of my scss assets on my ruby on rails project but they are applying just after rake assets:precompile and restarting rails server.
With JS files everything allright and they are changing on fly.
Possible problem is with compass gem.
That is my repo - https://github.com/tanotify/blog
And 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
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
end
Found solution! In config/environments/development.rb added line:
config.serve_static_assets = false

Rails stuck on post for a long time

Every time to POST a request
it takes me about 10~20 sec to stuck on the console.
What happened ? How to profile it ?
Started POST "/users" for 127.0.0.1 at 2015-01-07 11:20:43 +0800
Here's the gems are suspected to cause the slow response
gem 'quiet_assets'
gem "spring"
gem 'pry-rescue'
gem 'pry-byebug'
development.rb
# 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
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
--------------
I had a similar issue with slow performance, it became worse the larger your assets became. The solution, was that one line you have set to true in your development.rb file.
config.assets.debug = true
Change that to false and you should see a BIG improvement!

Resources