Reputation: 16513
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= stylesheet_link_tag 'authenticate', media: 'all', 'data-turbolinks-track' => true %>
I like to add one more style sheet "authenticate.css" along with "application.css" but I am getting error.
Sprockets::Rails::Helper::AssetFilteredError in <controller>#<action>
Asset filtered out and will not be served: add 'Rails.application.config.assets.precompile += %w( authenticate.css )' to 'config/initializers/assets.rb' and restart your server
If I am not wrong, this wasn't the case in rails 3, I don't like to add a line of code about "authenticate.css" in "config/initializers/assets.rb". Is this the only way to add a style sheet in view in Rails 4 or am I doing something wrong ?
I don't want it to be part of application.css by calling within it or by * require_tree .
. I just want to call it in the view where it's required but not in all the views.
Upvotes: 2
Views: 801
Reputation: 9173
I don't like to add a line of code about "authenticate.css" in "config/initializers/assets.rb". Is this the only way to add a style sheet in view in Rails 4 or am I doing something wrong ?
If you look at docs
, it says
If you have other manifests or individual stylesheets and JavaScript files to include, you can add them to the precompile array in config/initializers/assets.rb
so this line basically tell rails to precompile individual assets.
If I am not wrong, this wasn't the case in rails 3
If you look at this pull request
you'll see that sanity checks from the sprockets_better_errors gem have been merged into Rails 4.1. The intent is to reveal asset pipeline errors that you would see in production when you run the app in development mode
Upvotes: 1
Reputation: 370
Make sure *= require_tree is added in your application.css file, it will automatically add all the css which are inside your css folder and will need not to add them manually.
Upvotes: 0