Rails application does not serve asset in production mode with user assets folder

It works in development mode, but show me the error ActionController::RoutingError (No route matches [GET] "/lenord-single-page-theme/js/custom.js"):in production mode.

Before starting the rails server, I started RAILS_ENV=production rake assets:precompile --trace

I added two resource folders under the provider

in the application.rbfile, I insert the line

config.assets.paths << "#{Rails.root}/vendor/themes"

And changed config.serve_static_assetstotrue

+++ b/config/environments/production.rb
@@ -20,7 +20,7 @@ DqaStreesfulServer::Application.configure do
   # config.action_dispatch.rack_cache = true

   # Disable Rails static asset server (Apache or nginx will already do this).
-  config.serve_static_assets = false
+  config.serve_static_assets = true

Folder structure

vendor
β”œβ”€β”€ assets
β”‚   β”œβ”€β”€ javascripts
β”‚   └── stylesheets
└── themes
    β”œβ”€β”€ ace-admin-theme
    β”‚   β”œβ”€β”€ avatars
    β”‚   β”œβ”€β”€ css
    β”‚   β”œβ”€β”€ font
    β”‚   β”œβ”€β”€ images
    β”‚   β”œβ”€β”€ img
    β”‚   └── js
    └── lenord-single-page-theme
        β”œβ”€β”€ css
        β”œβ”€β”€ fonts
        β”œβ”€β”€ img
        β”œβ”€β”€ index.html
        β”œβ”€β”€ js
        └── rs-assets

UPDATE

I reference my js file this way

welcome.html.haml
60:  %script{src:  asset_path("lenord-single-page-theme/js/custom.js")}

UPDATE

I think the problem may be in production.rb

I tried to collect all the files by adding this line to production.rb

config.assets.precompile += %w( vendor/themes/* )

And I started the server in working mode with a command rails s -e production, notnginx or apache

UPDATE

I got ActionView::Template::Error (Invalid CSS after "}": expected selector or at-rule, was "}"in production mode after I made the following changes.

AT ../../config/environments/production.rb

+  config.assets.compile = true
+  config.assets.precompile = [/^[-_a-zA-Z0-9]*\..*/]
+  config.assets.precompile += %w( *.js *.css )

I showed a tree structure between Wendel / theme / and the public / assets here

It is reasonable?

in the public / assets section

% tree lenord-single-page-theme                                                                                                                               (git)-[feature/prettier_form] 
lenord-single-page-theme
└── js
    β”œβ”€β”€ application-dfabb3389cb2e71ba110a8589e5e106b.js
    └── application-dfabb3389cb2e71ba110a8589e5e106b.js.gz

//

lenord-single-page-theme
β”œβ”€β”€ css
β”‚   β”œβ”€β”€ animate.min.css
β”‚   β”œβ”€β”€ bootstrap.css
β”‚   β”œβ”€β”€ bootstrap.min.css
β”‚   β”œβ”€β”€ font-awesome.min.css
β”‚   β”œβ”€β”€ prettyPhoto.css
β”‚   β”œβ”€β”€ rs-settings-ie8.css
β”‚   β”œβ”€β”€ rs-settings.css
β”‚   └── style.css
β”œβ”€β”€ fonts
β”‚   β”œβ”€β”€ FontAwesome.otf
β”‚   β”œβ”€β”€ fontawesome-webfont.eot
β”‚   β”œβ”€β”€ fontawesome-webfont.svg
β”‚   β”œβ”€β”€ fontawesome-webfont.ttf
β”‚   └── fontawesome-webfont.woff
β”œβ”€β”€ img
β”‚   β”œβ”€β”€ 1.jpg
β”‚   β”œβ”€β”€ 10.jpg
β”‚   β”œβ”€β”€ 11.png
β”‚   β”œβ”€β”€ 12.jpg
β”‚   β”œβ”€β”€ 13.png
β”‚   β”œβ”€β”€ 2.jpg
β”‚   β”œβ”€β”€ 3.jpg
β”‚   β”œβ”€β”€ 4.png
β”‚   β”œβ”€β”€ 5.png
β”‚   β”œβ”€β”€ 6.png
β”‚   β”œβ”€β”€ 8.jpg
β”‚   β”œβ”€β”€ 9.jpg
β”‚   β”œβ”€β”€ aboutus.png
β”‚   β”œβ”€β”€ back-top.png
β”‚   β”œβ”€β”€ banner_1.jpg
β”‚   β”œβ”€β”€ banner_2.jpg
β”‚   β”œβ”€β”€ banner_3.jpg
β”‚   β”œβ”€β”€ blue-back.png
β”‚   β”œβ”€β”€ dummy.png
β”‚   β”œβ”€β”€ fback.png
β”‚   β”œβ”€β”€ portfolio
β”‚   β”‚   β”œβ”€β”€ 1.jpg
β”‚   β”‚   β”œβ”€β”€ 2.jpg
β”‚   β”‚   β”œβ”€β”€ 3.jpg
β”‚   β”‚   β”œβ”€β”€ 4.jpg
β”‚   β”‚   β”œβ”€β”€ 5.jpg
β”‚   β”‚   β”œβ”€β”€ 6.jpg
β”‚   β”‚   β”œβ”€β”€ 7.jpg
β”‚   β”‚   β”œβ”€β”€ 8.jpg
β”‚   β”‚   β”œβ”€β”€ 9.jpg
β”‚   β”‚   β”œβ”€β”€ tn1.jpg
β”‚   β”‚   β”œβ”€β”€ tn2.jpg
β”‚   β”‚   β”œβ”€β”€ tn3.jpg
β”‚   β”‚   β”œβ”€β”€ tn4.jpg
β”‚   β”‚   β”œβ”€β”€ tn5.jpg
β”‚   β”‚   β”œβ”€β”€ tn6.jpg
β”‚   β”‚   β”œβ”€β”€ tn7.jpg
β”‚   β”‚   β”œβ”€β”€ tn8.jpg
β”‚   β”‚   └── tn9.jpg
β”‚   β”œβ”€β”€ prettyPhoto
β”‚   β”‚   β”œβ”€β”€ dark_rounded
β”‚   β”‚   β”‚   β”œβ”€β”€ btnNext.png
β”‚   β”‚   β”‚   β”œβ”€β”€ btnPrevious.png
β”‚   β”‚   β”‚   β”œβ”€β”€ contentPattern.png
β”‚   β”‚   β”‚   β”œβ”€β”€ default_thumbnail.gif
β”‚   β”‚   β”‚   β”œβ”€β”€ loader.gif
β”‚   β”‚   β”‚   └── sprite.png
β”‚   β”‚   β”œβ”€β”€ dark_square
β”‚   β”‚   β”‚   β”œβ”€β”€ btnNext.png
β”‚   β”‚   β”‚   β”œβ”€β”€ btnPrevious.png
β”‚   β”‚   β”‚   β”œβ”€β”€ contentPattern.png
β”‚   β”‚   β”‚   β”œβ”€β”€ default_thumbnail.gif
β”‚   β”‚   β”‚   β”œβ”€β”€ loader.gif
β”‚   β”‚   β”‚   └── sprite.png
β”‚   β”‚   β”œβ”€β”€ default
β”‚   β”‚   β”‚   β”œβ”€β”€ default_thumb.png
β”‚   β”‚   β”‚   β”œβ”€β”€ loader.gif
β”‚   β”‚   β”‚   β”œβ”€β”€ sprite.png
β”‚   β”‚   β”‚   β”œβ”€β”€ sprite_next.png
β”‚   β”‚   β”‚   β”œβ”€β”€ sprite_prev.png
β”‚   β”‚   β”‚   β”œβ”€β”€ sprite_x.png
β”‚   β”‚   β”‚   └── sprite_y.png
β”‚   β”‚   β”œβ”€β”€ facebook
β”‚   β”‚   β”‚   β”œβ”€β”€ btnNext.png
β”‚   β”‚   β”‚   β”œβ”€β”€ btnPrevious.png
β”‚   β”‚   β”‚   β”œβ”€β”€ contentPatternBottom.png
β”‚   β”‚   β”‚   β”œβ”€β”€ contentPatternLeft.png
β”‚   β”‚   β”‚   β”œβ”€β”€ contentPatternRight.png
β”‚   β”‚   β”‚   β”œβ”€β”€ contentPatternTop.png
β”‚   β”‚   β”‚   β”œβ”€β”€ default_thumbnail.gif
β”‚   β”‚   β”‚   β”œβ”€β”€ loader.gif
β”‚   β”‚   β”‚   └── sprite.png
β”‚   β”‚   β”œβ”€β”€ light_rounded
β”‚   β”‚   β”‚   β”œβ”€β”€ btnNext.png
β”‚   β”‚   β”‚   β”œβ”€β”€ btnPrevious.png
β”‚   β”‚   β”‚   β”œβ”€β”€ default_thumbnail.gif
β”‚   β”‚   β”‚   β”œβ”€β”€ loader.gif
β”‚   β”‚   β”‚   └── sprite.png
β”‚   β”‚   └── light_square
β”‚   β”‚       β”œβ”€β”€ btnNext.png
β”‚   β”‚       β”œβ”€β”€ btnPrevious.png
β”‚   β”‚       β”œβ”€β”€ default_thumbnail.gif
β”‚   β”‚       β”œβ”€β”€ loader.gif
β”‚   β”‚       └── sprite.png
β”‚   β”œβ”€β”€ product.png
β”‚   β”œβ”€β”€ service
β”‚   β”‚   β”œβ”€β”€ 11.png
β”‚   β”‚   β”œβ”€β”€ 12.png
β”‚   β”‚   β”œβ”€β”€ 21.png
β”‚   β”‚   β”œβ”€β”€ 22.png
β”‚   β”‚   β”œβ”€β”€ 31.png
β”‚   β”‚   β”œβ”€β”€ 32.png
β”‚   β”‚   β”œβ”€β”€ 41.png
β”‚   β”‚   └── 42.png
β”‚   β”œβ”€β”€ service.png
β”‚   β”œβ”€β”€ vast.jpg
β”‚   β”œβ”€β”€ vivotek_square_icon.jpg
β”‚   β”œβ”€β”€ vvtk_sd.jpg
β”‚   └── wood-back.png
β”œβ”€β”€ index.html
β”œβ”€β”€ js
β”‚   β”œβ”€β”€ application.js
β”‚   β”œβ”€β”€ bootstrap.js
β”‚   β”œβ”€β”€ bootstrap.min.js
β”‚   β”œβ”€β”€ custom.js
β”‚   β”œβ”€β”€ gmaps.js
β”‚   β”œβ”€β”€ html5shiv.js
β”‚   β”œβ”€β”€ jquery.arbitrary-anchor.js
β”‚   β”œβ”€β”€ jquery.js
β”‚   β”œβ”€β”€ jquery.knob.js
β”‚   β”œβ”€β”€ jquery.prettyPhoto.js
β”‚   β”œβ”€β”€ jquery.themepunch.plugins.min.js
β”‚   β”œβ”€β”€ jquery.themepunch.revolution.min.js
β”‚   β”œβ”€β”€ respond.min.js
β”‚   └── waypoints.min.js
└── rs-assets
    β”œβ”€β”€ arrow_large_left.png
    β”œβ”€β”€ arrow_large_right.png
    β”œβ”€β”€ arrow_left.png
    β”œβ”€β”€ arrow_left2.png
    β”œβ”€β”€ arrow_right.png
    β”œβ”€β”€ arrow_right2.png
    β”œβ”€β”€ arrowleft.png
    β”œβ”€β”€ arrowright.png
    β”œβ”€β”€ arrows.psd
    β”œβ”€β”€ black50.png
    β”œβ”€β”€ boxed_bgtile.png
    β”œβ”€β”€ bullet.png
    β”œβ”€β”€ bullet_boxed.png
    β”œβ”€β”€ bullets.png
    β”œβ”€β”€ bullets.psd
    β”œβ”€β”€ bullets2.png
    β”œβ”€β”€ coloredbg.png
    β”œβ”€β”€ grain.png
    β”œβ”€β”€ large_left.png
    β”œβ”€β”€ large_right.png
    β”œβ”€β”€ loader.gif
    β”œβ”€β”€ loader2.gif
    β”œβ”€β”€ navigdots.png
    β”œβ”€β”€ navigdots_bgtile.png
    β”œβ”€β”€ shadow1.png
    β”œβ”€β”€ shadow2.png
    β”œβ”€β”€ shadow3.png
    β”œβ”€β”€ small_arrows.psd
    β”œβ”€β”€ small_left.png
    β”œβ”€β”€ small_left_boxed.png
    β”œβ”€β”€ small_right.png
    β”œβ”€β”€ small_right_boxed.png
    β”œβ”€β”€ timer.png
    β”œβ”€β”€ timerdot.png
    β”œβ”€β”€ transparent.jpg
    └── white50.png

14 directories, 154 files
+4
1

: app/assets, lib/assets vendor/assets. / /.

:

config.assets.precompile += ['vendor/themes/lenord-single-page-theme/js/*.js']
config.assets.precompile += ['vendor/themes/lenord-single-page-theme/css/*.css']

:

RAILS_ENV=production bundle exec rake assets:precompile

public/assets:

//Lenord--/JS/custom.js

Lenord--/JS/custom.js

:

javascript_include_tag "PATH_OF_THE_ASSET"

:

javascript_include_tag "lenord-single-page-theme/js/custom.js"

javascript_include_tag "//Lenord--/JS/custom.js"

+1

Source: https://habr.com/ru/post/1541207/


All Articles