Precompiling Rails 5 to include all assets

I am trying to precompile all my assets for production. When I run RAILS_ENV=production bundle exec rake assets:precompile , not all of my assets are precompiled. I tried using methods that others suggested in other similar issues, but they did not work for me. To get started, here is what my assets.rb looks like:

 Rails.application.config.assets.version = '1.0' Rails.application.config.assets.paths << Rails.root.join('node_modules') Rails.application.config.assets.precompile += %w(creative/manifest.js creative/manifest.css images/* bootstrap/* fonts/* magnific-popup/* morphext/* owlcarousel2/* rs-plugin-5/* stylesheets/* javascripts/*) 

As you can see where I am precompiling, I tried adding, for example, directory/* to include everything. Here are the files I'm trying to include, and everything in them (they are in the Assets directory):

 bootstrap fonts javascripts morphext rs-plugin-5 config images magnific-popup owlcarousel2 stylesheets 

Here is what is precompiled in my public directory, when I run the precompilation, look at the image in the open air, and, as you can see, many of the directories are not there, I even opened each folder to see, in a different folder and nothing does not exist:

public directory

The last part is when I run rails s -e production and I go to Localhost:3000 . I keep getting 500 error and nothing is displayed. There are no errors in the console in the chrome or terminal, so I don’t see how my page on the local computer for production will look. Any help would be appreciated.

Update

Here is my production.log, it looks like it is not getting the necessary assets:

 I, [2017-09-12T18:43:54.606853 #7393] INFO -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] Started GET "/" for 127.0.0.1 at 2017-09-12 18:43:54 -0700 I, [2017-09-12T18:43:54.625461 #7393] INFO -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] Processing by CreativesController#index as HTML I, [2017-09-12T18:43:54.642161 #7393] INFO -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] Rendering creatives/index.html.erb within layouts/application I, [2017-09-12T18:43:54.644418 #7393] INFO -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] Rendered creatives/index.html.erb within layouts/application (2.1ms) I, [2017-09-12T18:43:54.644629 #7393] INFO -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] Completed 500 Internal Server Error in 19ms F, [2017-09-12T18:43:54.645433 #7393] FATAL -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] F, [2017-09-12T18:43:54.645478 #7393] FATAL -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] ActionView::Template::Error (The asset "AdobeStock_95578405.jpeg" is not present in the asset pipeline.): F, [2017-09-12T18:43:54.645761 #7393] FATAL -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] 17: <li data-transition="slidehorizontal" data-slotamount="default" data-masterspeed="default" data-title="Next Generation Care"> [b2f4fb53-c1ea-4d59-8045-44167c60416c] 18: [b2f4fb53-c1ea-4d59-8045-44167c60416c] 19: <!-- main image --> [b2f4fb53-c1ea-4d59-8045-44167c60416c] 20: <%= image_tag "AdobeStock_95578405.jpeg" ,alt: "slidebg1", :data => {bgposition: "center bottom",bgrepeat: "no-repeat", bgfit: "cover"} , :class => "rev-slidebg" %> [b2f4fb53-c1ea-4d59-8045-44167c60416c] 21: [b2f4fb53-c1ea-4d59-8045-44167c60416c] 22: <!-- Transparent Background --> [b2f4fb53-c1ea-4d59-8045-44167c60416c] 23: <div class="tp-caption dark-translucent-bg" F, [2017-09-12T18:43:54.645799 #7393] FATAL -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] F, [2017-09-12T18:43:54.645828 #7393] FATAL -- : [b2f4fb53-c1ea-4d59-8045-44167c60416c] app/views/creatives/index.html.erb:20:in `_app_views_creatives_index_html_erb___200307797594027740_70304554688000' I, [2017-09-12T18:43:54.734601 #7393] INFO -- : [8f353cbb-4884-4c2c-896d-ba60b58caa61] Started GET "/favicon.ico" for 127.0.0.1 at 2017-09-12 18:43:54 -0700 F, [2017-09-12T18:43:54.735010 #7393] FATAL -- : [8f353cbb-4884-4c2c-896d-ba60b58caa61] F, [2017-09-12T18:43:54.735048 #7393] FATAL -- : [8f353cbb-4884-4c2c-896d-ba60b58caa61] ActionController::RoutingError (No route matches [GET] "/favicon.ico"): F, [2017-09-12T18:43:54.735071 #7393] FATAL -- : [8f353cbb-4884-4c2c-896d-ba60b58caa61] F, [2017-09-12T18:43:54.735100 #7393] FATAL -- : [8f353cbb-4884-4c2c-896d-ba60b58caa61] actionpack (5.1.3) lib/action_dispatch/middleware/debug_exceptions.rb:63:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] actionpack (5.1.3) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] railties (5.1.3) lib/rails/rack/logger.rb:36:in `call_app' [8f353cbb-4884-4c2c-896d-ba60b58caa61] railties (5.1.3) lib/rails/rack/logger.rb:24:in `block in call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] activesupport (5.1.3) lib/active_support/tagged_logging.rb:69:in `block in tagged' [8f353cbb-4884-4c2c-896d-ba60b58caa61] activesupport (5.1.3) lib/active_support/tagged_logging.rb:26:in `tagged' [8f353cbb-4884-4c2c-896d-ba60b58caa61] activesupport (5.1.3) lib/active_support/tagged_logging.rb:69:in `tagged' [8f353cbb-4884-4c2c-896d-ba60b58caa61] railties (5.1.3) lib/rails/rack/logger.rb:24:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] actionpack (5.1.3) lib/action_dispatch/middleware/remote_ip.rb:79:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] actionpack (5.1.3) lib/action_dispatch/middleware/request_id.rb:25:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] rack (2.0.3) lib/rack/method_override.rb:22:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] rack (2.0.3) lib/rack/runtime.rb:22:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] activesupport (5.1.3) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] actionpack (5.1.3) lib/action_dispatch/middleware/executor.rb:12:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] rack (2.0.3) lib/rack/sendfile.rb:111:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] railties (5.1.3) lib/rails/engine.rb:522:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] puma (3.10.0) lib/puma/configuration.rb:225:in `call' [8f353cbb-4884-4c2c-896d-ba60b58caa61] puma (3.10.0) lib/puma/server.rb:605:in `handle_request' [8f353cbb-4884-4c2c-896d-ba60b58caa61] puma (3.10.0) lib/puma/server.rb:437:in `process_client' [8f353cbb-4884-4c2c-896d-ba60b58caa61] puma (3.10.0) lib/puma/server.rb:301:in `block in run' [8f353cbb-4884-4c2c-896d-ba60b58caa61] puma (3.10.0) lib/puma/thread_pool.rb:120:in `block in spawn_thread' I, [2017-09-12T18:43:58.249911 #7393] INFO -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] Started GET "/" for 127.0.0.1 at 2017-09-12 18:43:58 -0700 I, [2017-09-12T18:43:58.251066 #7393] INFO -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] Processing by CreativesController#index as HTML I, [2017-09-12T18:43:58.252212 #7393] INFO -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] Rendering creatives/index.html.erb within layouts/application I, [2017-09-12T18:43:58.253079 #7393] INFO -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] Rendered creatives/index.html.erb within layouts/application (0.7ms) I, [2017-09-12T18:43:58.253250 #7393] INFO -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] Completed 500 Internal Server Error in 2ms F, [2017-09-12T18:43:58.254061 #7393] FATAL -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] F, [2017-09-12T18:43:58.254123 #7393] FATAL -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] ActionView::Template::Error (The asset "AdobeStock_95578405.jpeg" is not present in the asset pipeline.): F, [2017-09-12T18:43:58.254377 #7393] FATAL -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] 17: <li data-transition="slidehorizontal" data-slotamount="default" data-masterspeed="default" data-title="Next Generation Care"> [2e6342ac-ec61-410c-98ba-ae205fb9cc26] 18: [2e6342ac-ec61-410c-98ba-ae205fb9cc26] 19: <!-- main image --> [2e6342ac-ec61-410c-98ba-ae205fb9cc26] 20: <%= image_tag "AdobeStock_95578405.jpeg" ,alt: "slidebg1", :data => {bgposition: "center bottom",bgrepeat: "no-repeat", bgfit: "cover"} , :class => "rev-slidebg" %> [2e6342ac-ec61-410c-98ba-ae205fb9cc26] 21: [2e6342ac-ec61-410c-98ba-ae205fb9cc26] 22: <!-- Transparent Background --> [2e6342ac-ec61-410c-98ba-ae205fb9cc26] 23: <div class="tp-caption dark-translucent-bg" F, [2017-09-12T18:43:58.254415 #7393] FATAL -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] F, [2017-09-12T18:43:58.254442 #7393] FATAL -- : [2e6342ac-ec61-410c-98ba-ae205fb9cc26] app/views/creatives/index.html.erb:20:in `_app_views_creatives_index_html_erb___200307797594027740_70304554688000' 

UPDATE 2

Here is an image of the folder structure of my resource:

Asset path

I also noticed that there is another folder with resources, because it precompiles the rs-plugin structure, and not other folders that see the image:

rs plugin

Here is my .rb application:

 require_relative 'boot' require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module Cnd class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.1 config.assets.paths << Rails.root.join("app", "assets", "fonts") config.assets.paths << Rails.root.join("app", "assets", "images") config.assets.paths << Rails.root.join("app", "assets", "bootstrap") config.assets.paths << Rails.root.join("app", "assets", "rs-plugin-5") config.assets.paths << Rails.root.join("app", "assets", "magnific-popup") config.assets.paths << Rails.root.join("app", "assets", "owlcarousel2") config.assets.paths << Rails.root.join("app", "assets", "morphext") # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. end end 
+5
source share
3 answers

Make sure of this first if you want your rail application to be serviced.

 # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?` 

Regarding asset compilation, keep in mind that you might need to add ou.js to your application.css if you are talking about css or js respectively. Check it out.

For example (as in the link above)

 app/assets/javascripts/home.js lib/assets/javascripts/moovinator.js vendor/assets/javascripts/slider.js vendor/assets/somepackage/phonebox.js 

will be referenced in the manifest as follows:

 //= require home //= require moovinator //= require slider //= require phonebox 

Access to assets within subdirectories.

 app/assets/javascripts/sub/something.js 

refers to:

 //= require sub/something 

A few notes I noticed:

  • You have a resource folder in another resource folder. This does not seem right.
  • Can you show me your resource directory where you have this AdobeStock_95578405.jpeg image?
  • Add Rails.application.config.assets.precompil to the config / initializer / assets.rb file.
  • Oh btw, make sure you restart your server every time you make changes by checking this. I have already spent too many hours just because I completely forgot about this thing.
+6
source
 Rails.application.config.assets.precompile += %w(creative/manifest.js creative/manifest.css images/* bootstrap/* fonts/* magnific-popup/* morphext/* owlcarousel2/* rs-plugin-5/* stylesheets/* javascripts/*) 

but, as I see from your screenshot, you have a folder named assets inside your public/assets directory.

Precompiled fingerprint files are inside public/assets/assets instead of public/assets

This means that if these files click on production (check that they are in your git repository, if you do not do git add ), you will not be able to see them in the localhost:3000/assets/<nameofyourfile> path localhost:3000/assets/<nameofyourfile> because your directory structure is changed maybe you can map them to localhost:3000/assets/assets/<nameofyourfile> , but if I were you, I would keep the usual directory structure.

Precompiling your assets means creating a printed version of it

Saying , I want to precompile all my assets , you say that you want all files added or edited in the pipeline of your resource to generate a pre-compiled version of the fingerprint that will be used in production.

How does precompilation work? You can read Chapter 4.1 of the Asset Pipeline Documentation , mostly stars use a file called .sprockets-manifest-fingerprint.json to check which one is the latest version of fingerprint files for use in production. This is why sometimes deleting the public/assets folder solves the problem, because you delete all old files, including sprockets-manifest.json , which may not be updated with the last fingerprint.

Also, development will drop from the files in your app/assets folder if it does not find them in your public/assets folder, so you get an error only during the production process. You can read how to disable this behavior.

chapter 3.1 and 3.2

So, take these steps, because bugs are usually easier to solve during the development process, since you do not need to press git to see the result. Sometimes files are included in .gitignore or you need to manually add this file using git add app/assets/<nameofthefolder>/<nameofthefile>

We also saw your public folder in the screenshot, but we did not see you in the app/assets folder structure and any of your star settings, so maybe it's not about adding generosity to the question to get a solution, but just giving us information, necessary to find a solution.

Now this is a general opinion based question.

Also, I believe that you changed the /assets path by doing config.assets.prefix = "/some_other_path"

+6
source

This may not be right, but it looks like you left config from the list of precompiled directories. Try updating the list:

 Rails.application.config.assets.precompile += %w(creative/manifest.js creative/manifest.css images/* bootstrap/* fonts/* magnific-popup/* morphext/* owlcarousel2/* rs-plugin-5/* stylesheets/* javascripts/* config/*) 
+3
source

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


All Articles