by
back

Use the logger in views in Ruby on Rails

If you try to use for example logger.fatal in a view, then you will get an error like this:

ActionView::Template::Error (undefined method `fatal' for nil:NilClass)

The error will occur if you try something like this in a rails view:

wrong

<% logger.fatal "Lorem Ipsum" %>

Just call Rails.logger instead and the error is gone:

right

<% Rails.logger.fatal "Lorem Ipsum" %>


comments powered by Disqus