A
A
Anton2016-01-19 23:41:24
Ruby on Rails
Anton, 2016-01-19 23:41:24

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:
f4f1f5cfd16a4112810fe035e4bcc966.png
This is because of this code:

<% if current_user.has_role? :admin %>
    Есть доступ админа
<% else %>
    Нет доступа админа
<% end %>

Log snippet:
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'

I don't understand why this is so, because I did everything according to the official documentation... Okay, I deleted this piece of code for a while.
Restarted the project. But now another trouble:
9ac48fa26d1c44f6aa2411784466e118.png
This is about files:
site.ru/stylesheets/home.css
site.ru/javascripts/application.js
The layer in the head has this:
<%= stylesheet_link_tag    'home', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

This was not the case in the development version. I don’t even understand what css is and why he is trying to get it from somewhere. Like always sass files cling.
Briefly speaking. These are two big problems that now worry and distract me very much.
Please help me fix them.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeniy Trebin, 2016-01-20
@hummingbird

Try this

<% if user_signed_in? && current_user.has_role?(:admin) %>
    Есть доступ админа
<% else %>
    Нет доступа админа
<% end %>

or in the controller add
before_action :authenticate_user!

M
Mikhail Beloshitsky, 2016-01-20
@mbeloshitsky

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

The main thing is not to forget to return everything back later.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question