A
A
arruah2019-01-13 08:27:15
Ruby on Rails
arruah, 2019-01-13 08:27:15

How to find out the reason why Ruby on Rails is not loading styles?

I'm trying to package a RoR project in docker using docker-compose. The project starts but styles are not loaded. This is in the logs:

I, [2019-01-13T05:25:34.400480 #1]  INFO -- : Started GET "/body/list/all" for 172.23.0.1 at 2019-01-13 05:25:34 +0000
I, [2019-01-13T05:25:34.406057 #1]  INFO -- : Processing by PublicBodyController#list as HTML
I, [2019-01-13T05:25:34.481372 #1]  INFO -- :   Rendered public_body/_body_listing.html.erb (1.2ms)
I, [2019-01-13T05:25:34.485731 #1]  INFO -- :   Rendered public_body/_alphabet.html.erb (3.5ms)
I, [2019-01-13T05:25:34.493234 #1]  INFO -- :   Rendered public_body/_list_sidebar_extra.html.erb (1.0ms)
I, [2019-01-13T05:25:34.493418 #1]  INFO -- :   Rendered public_body/list.html.erb within layouts/default (14.5ms)
I, [2019-01-13T05:25:34.494712 #1]  INFO -- :   Rendered layouts/_favicon.html.erb (0.4ms)
I, [2019-01-13T05:25:34.496835 #1]  INFO -- :   Rendered general/_responsive_stylesheets.html.erb (0.8ms)
I, [2019-01-13T05:25:34.497232 #1]  INFO -- :   Rendered general/_stylesheet_includes.html.erb (1.9ms)
I, [2019-01-13T05:25:34.498290 #1]  INFO -- :   Rendered general/_opengraph_tags.html.erb (0.4ms)
I, [2019-01-13T05:25:34.499673 #1]  INFO -- :   Rendered lib/themes/alavetelitheme/lib/views/general/_before_head_end.html.erb (0.6ms)
I, [2019-01-13T05:25:34.510512 #1]  INFO -- :   Rendered general/_locale_switcher.html.erb (0.2ms)
I, [2019-01-13T05:25:34.511186 #1]  INFO -- :   Rendered general/_log_in_bar.html.erb (0.3ms)
I, [2019-01-13T05:25:34.523354 #1]  INFO -- :   Rendered general/_nav_items.html.erb (0.9ms)
I, [2019-01-13T05:25:34.523524 #1]  INFO -- :   Rendered general/_responsive_topnav.html.erb (11.7ms)
I, [2019-01-13T05:25:34.523657 #1]  INFO -- :   Rendered general/_responsive_header.html.erb (14.2ms)
I, [2019-01-13T05:25:34.525045 #1]  INFO -- :   Rendered general/_responsive_credits.html.erb (0.2ms)
I, [2019-01-13T05:25:34.529978 #1]  INFO -- :   Rendered general/_responsive_footer.html.erb (5.7ms)
I, [2019-01-13T05:25:34.531204 #1]  INFO -- :   Rendered lib/themes/alavetelitheme/lib/views/general/_before_body_end.html.erb (0.5ms)
I, [2019-01-13T05:25:34.531496 #1]  INFO -- : Completed 200 OK in 125ms (Views: 37.4ms | ActiveRecord: 66.1ms)
I, [2019-01-13T05:25:34.546144 #1]  INFO -- : Started GET "/stylesheets/responsive/application.css" for 172.23.0.1 at 2019-01-13 05:25:34 +0000
I, [2019-01-13T05:25:34.551177 #1]  INFO -- : Processing by GeneralController#not_found as CSS
I, [2019-01-13T05:25:34.551243 #1]  INFO -- :   Parameters: {"path"=>"stylesheets/responsive/application"}
I, [2019-01-13T05:25:34.552297 #1]  INFO -- : Completed 404 Not Found in 1ms (ActiveRecord: 0.0ms)
I, [2019-01-13T05:25:34.554729 #1]  INFO -- : Started GET "/javascripts/application.js" for 172.23.0.1 at 2019-01-13 05:25:34 +0000
I, [2019-01-13T05:25:34.559508 #1]  INFO -- : Processing by GeneralController#not_found as JS
I, [2019-01-13T05:25:34.559613 #1]  INFO -- :   Parameters: {"path"=>"javascripts/application"}
I, [2019-01-13T05:25:34.560663 #1]  INFO -- : Completed 404 Not Found in 1ms (ActiveRecord: 0.0ms)
I, [2019-01-13T05:25:34.563017 #1]  INFO -- : Started GET "/stylesheets/responsive/print.css" for 172.23.0.1 at 2019-01-13 05:25:34 +0000
I, [2019-01-13T05:25:34.567878 #1]  INFO -- : Processing by GeneralController#not_found as CSS
I, [2019-01-13T05:25:34.567976 #1]  INFO -- :   Parameters: {"path"=>"stylesheets/responsive/print"}
I, [2019-01-13T05:25:34.569313 #1]  INFO -- : Completed 404 Not Found in 1ms (ActiveRecord: 0.0ms)
I, [2019-01-13T05:25:34.593278 #1]  INFO -- : Started GET "/images/favicon.ico" for 172.23.0.1 at 2019-01-13 05:25:34 +0000
I, [2019-01-13T05:25:34.597898 #1]  INFO -- : Processing by GeneralController#not_found as 
I, [2019-01-13T05:25:34.597971 #1]  INFO -- :   Parameters: {"path"=>"images/favicon"}
I, [2019-01-13T05:25:34.598964 #1]  INFO -- : Completed 404 Not Found in 1ms (ActiveRecord: 0.0ms)

Although the files on which he complains are present.
If I deploy the same project using vagrant, then everything works fine.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Roman Mirilaczvili, 2019-01-13
@2ord

You need to precompile assets,
then refresh the page with Ctrl-F5 to pick up the paths of the new style files. You can also restart your browser. In DevTools, in the Network tab, you need to observe which paths are used to access styles.
In general, it is difficult to guess without code. If the above does not help, then I will assume that the matter is in the Gemfile file or the initialization of the framework.

Z
Zaporozhchenko Oleg, 2019-01-13
@c3gdlk

Your vargrant is most likely configured for development, and in docker you are trying to run it in production. Ruby is slow to distribute assets, so the rail does not distribute them by default in production, relying on nginx to do this.
Therefore, you need to either add nginx to docker, or set serve_static_assets = true in production.rb
In addition, you need to make sure that all assets are compiled, those that are not added to assets.rb in initializers

D
dexdev, 2019-01-13
@AdilA

Try the old-fashioned capistrano nginx method, first you will understand how it all works, then you will package it in docker. Or don't worry and find DevOps.
habrahabr.ru/post/240025 to help, it helped me a lot at one time.

V
vsuhachev, 2019-01-14
@vsuhachev

You can use 2 options:
First: compile the assets before building the image and pack `public/assets` into the image. And then cling this folder as a volume to the nginx container and write the appropriate config for nginx
Second: compile assets in the container (enable servse_static_assets in rails) and configure caching for assets on the web server side.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question