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 )
toconfig/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.
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.
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.
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.
you just try this..
check your Gemfile
gem 'sprockets-rails', '2.3.3'
And bundle install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With