Answer the question
In order to leave comments, you need to log in
How to fix problems in the production version of a RoR project?
Hello!
I was developing a project in the development version (namely, I was fiddling with CanCanCan) and for a moment it became interesting, but what access errors look like in the production version. It never came to that...
The project started without any problems, but this was posted on the site:
This is because of this code:
<% if current_user.has_role? :admin %>
Есть доступ админа
<% else %>
Нет доступа админа
<% end %>
ActionView::Template::Error (undefined method `has_role?' for nil:NilClass):
2:
3: <%= notice %>
4:
5: <% if current_user.has_role? :admin %>
6: Have admin access
7: <% else %>
8: No admin access
app/views/home/index.html.erb:5:in `_app_views_home_index_html_erb___2839417483853351120_70310855782180'
<%= stylesheet_link_tag 'home', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
Answer the question
In order to leave comments, you need to log in
Try this
<% if user_signed_in? && current_user.has_role?(:admin) %>
Есть доступ админа
<% else %>
Нет доступа админа
<% end %>
before_action :authenticate_user!
I will add that there is still a way to make the production version temporarily start behaving like a debug version (give errors with a stack trace, etc.) - in config/environments/production.rb, invert the flag values
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question