Rails 3 ActionView::Template::Error: ActionView::Template::Error - ruby-on-rails

I am upgrading my application from Rails 2.3.14 to Rails 3.0.1
I always get this error if there is any error in the view
Development mode eh? Here is the error - #<ActionView::Template::Error: ActionView::Template::Error>
app/controllers/application_controller.rb:158:in `render_500'
This is the code written for render_500 in application_controller.rb
def render_500(error)
if Rails.env.production?
render :file => Rails.root.join('public','access_denied.html'), :status => 500
else
raise Exception, I18n.t('str_error')+" - #{error.inspect}"
end
end
I am debugging the code now by writing puts statements.
Please help me with a solution. Thanks in advance.

Well, the application is behaving properly. The Development mode eh? Here is the error is the string inside I18n.t('str_error'). You are just raising an exception, and rendering nothing, just this string, so there is no problem.
Template error can be many things, but the one more common is assets that are not precompiled and stuff. Do a little research on this, maybe it is the problem, but keep in mind that the code provided is working as expected.

Related

How to debug EOFError raised from Devise actions?

I have started getting a strange issue in a Rails app, that is proving very difficult to debug.
EOFError
end of file reached
is being raised on some Devise routes. So far I'm getting this on session#destroy and registration#update (I have not been able to try others).
The issue is not occurring in tests, only in development environment.
After stepping through the controllers, the error appears to be raised on the following lines.
registration#update
resource_updated = update_resource(resource, account_update_params)
session#destroy
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
I realise that identifing the cause will likely need much more code. But after several hours trying to debug this I'm at a loss to next steps. I'd be grateful if anyone can:
Suggest how to obtain more useful information when EOFError is
raised. Currently all I'm getting is Completed 500 Internal Server
Error in 2627ms (ActiveRecord: 10.1ms) EOFError - end of file
reached: without much to identify where this is being raised.
Suggest a logical approach to debug this. From my attempts, the
error appears to be coming from the Devise internals, which I don't
think is correct.

Rails 3.2.13, 500 error in development with no log

I've got problem with migrating rails 2.x -> 3.2.13
At some point, after fixing a few things, I get Completed 500 Internal Server Error in 76ms without any traceback.
development.rb
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
Why there is no traceback and how to fix this?
you probably solved it but I wanted to share my couple of hours debugging about this issue as it can be very annoying. In short, I was having the same problem - 500 internal server error without any log of the exception thrown. It was happening only for exceptions thrown in the action view templates - any ActionView::Template::Error exception. For example, missing partial, invalid route.
My specific problem was using this ruby statistics module:
http://derrick.pallas.us/ruby-stats/
directly in the initializers directory which works great in rails 2.x. It defined Array.sum method which is already defined in rails 3 under Enumerable.sum. The problem with the redefine is that Array.sum no longer works with arrays of strings which is what rails was trying to do with ActionView::Template::Error.source_extract method - when trying to extract the source of the error in template, it uses the Enumerable.sum method which is redefined in a wrong way. Thus, another exception happened TypeError: cannot convert String into Fixnum and the original exception was not logged, neither was the new one. I had to do a backtrace and go through many of the internal calls to see where is the issue.
So, for everyone not seeing the actual exceptions thrown in your ActionView templates, check if you have not redefined a rails method that is used internally in rails.

Rails doesn't log template errors in development mode

My Rails 3.2.9-app does not show any specific error information to me on errors in templates! It doesn't matter if I use haml or erb, I am always getting
"We're sorry, but something went wrong"
In fact, Webrick is in development mode and if there are errors in my models or controllers, I get the full ordinary error screen.
Examples
Example error in my helper-template ("#resource" does not exist, must be "resource"):
-> All I get is this lousy "We are sorry, but something went wrong"
<% #resource.errors.full_messages.each do |msg| %>
Example error in one of my controllers:
resposnd_to do |format|
-> undefined method `resposnd_to' for ...
I finally solved this problem!! All in all, I searched for more than 1 year, but now, i finally got the solution:
The problem is to use umlauts or blank spaces in the path of the rails project. If you move your rails project to a path without umlauts or blanks, the error message should be shown properly :-)!
Tested on ubuntu-machine, maybe this is important for this bug. This bug appears in rails 3.2.9, 3.2.13 and 3.2.14 definitely.
(consider_all_requests_local is activated of course, this never was the reason)

Rails full error page not showing for view errors

I have a view named new.html.erb with the following code:
<%= some_non_existent_thing.imaginary_method %>
Now, I only see one simple 500 error page, like that:
500 Internal Server Error
If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.
Shouldn't I see a pretty formatted page with some information about the exception?
I'm not sure I miss something here, but I believe rails used to show the full error page in development environment when there is something wrong in the view.
Are you sure that you are running the development environment? Check that RAILS_ENV=development or that you are running rails server -e development.
Then check your development.rb file, you should have the following line in it
config.consider_all_requests_local = true
If you happen to have an exception inside an exception, Rails has a middleware that catches it and returns a FAILSAFE_RESPONSE with the following copy:
500 Internal Server Error
If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.
A nice way to troubleshoot this is to compare your custom error code with the sample code provided in the Rails 4.2.0 guides.
I'm pointing to that particular version because that whole section was removed in the Rails 5.0.0 guides.
Ideally, you should keep your error views, layout, and controller as free of logic as possible, to avoid running into this issue.
Firstly, as Anton mentions in the answer below, confirm that your config/environments/development.rb has:
config.consider_all_requests_local = true
and that you are running the server in development mode.
I had ensured the above and still observed the error.
This happened in my case, because my logger had some errors. I was using a custom log formatter, which used the String#% method to format the log. % seems to be very buggy and leads to all these weird errors. I figured this one out by adding a debugger line to the controller method and stepping through into the implicit render function call. It hit the bug and reported it as a malformed format string error.
This was the log formatter I was using before, which caused the bugs [I had added it to an initializer file]:
class Logger::SimpleFormatter
def call(severity, time, progname, msg)
"%-7s #{msg}\n" % severity
end
end
These modifications fixed the bug:
class Logger::SimpleFormatter
def call(severity, time, progname, msg)
severity_prefix = "[#{severity}]".ljust(7)
"#{severity_prefix} #{msg}\n"
end
end
This happens if the code is not compilable, for example if you have an if statement missing an end.

Rails: errors in production vs development

In Rails, is there a way to display different error messages on a production rails server (a nice graphic) vs a development server (detailed error information, stack trace, etc.)?
Found one solution. In ApplicationController, add:
rescue_from Exception, :with => :rescue_all_exceptions if RAILS_ENV == 'production'
def rescue_all_exceptions(exception)
case exception
# do production-ey exception stuff
end
end
I'd be interested to hear other options...

Resources