Search code examples
ruby-on-rails-5

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.


Solution

  • you just try this..

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

    And bundle install