Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asset was not declared to be precompiled in production (Rails 5.0.0.1)

I am new to Rails 5.0.0.1

I followed the guidelines in http://guides.rubyonrails.org/asset_pipeline.html#controller-specific-assets:

You can also opt to include controller specific stylesheets and JavaScript files only in their respective controllers using the following:

<%= javascript_include_tag params[:controller] %> or <%= stylesheet_link_tag params[:controller] %>

When doing this, ensure you are not using the require_tree directive, as that will result in your assets being included more than once.

I generated some scaffolds (which also generated the assets -- .coffee and .scss)

When I do rails s and access one of the scaffold's main page, it generated an error:

Asset was not declared to be precompiled in production.

Add Rails.application.config.assets.precompile += %w( myscaffold.css ) to config/initializers/assets.rb and restart your server


I do as it said, and it worked, but is there any other way to simplify this process?

I wish that I can generate some other scaffolds or controllers with their assets without doing any more concern of adding new lines inside the config/initializers/assets.rb.

I will receive any other alternatives too.

like image 741
Aranda Soedjono Avatar asked Dec 03 '16 10:12

Aranda Soedjono


People also ask

What is assets precompile in Rails?

By default, Rails uses CoffeeScript for JavaScript and SCSS for CSS. DHH has a great introduction during his keynote for RailsConf. The Rails asset pipeline provides an assets:precompile rake task to allow assets to be compiled and cached up front rather than compiled every time the app boots.

What is require_ tree in Rails?

The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file.

How does Rails asset pipeline work?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.


1 Answers

you just try this..

check your Gemfile gem 'sprockets-rails', '2.3.3'

And bundle install

like image 128
Karthick Nagarajan Avatar answered Sep 25 '22 19:09

Karthick Nagarajan