Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #14689 from matthewd/asset_initializer

Move assets precompile (and version) to an initializer
  • Loading branch information...
commit f166f1da4631966181020118cd950f3111f83d61 2 parents f1a4f0a + f612c2b
@rafaelfranca rafaelfranca authored
8 guides/source/asset_pipeline.md
@@ -709,17 +709,17 @@ JS/CSS is excluded, as well as raw JS/CSS files; for example, `.coffee` and
`.scss` files are **not** automatically included as they compile to JS/CSS.
If you have other manifests or individual stylesheets and JavaScript files to
-include, you can add them to the `precompile` array in `config/application.rb`:
+include, you can add them to the `precompile` array in `config/initializers/assets.rb`:
```ruby
-config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
+Rails.application.config.assets.precompile += ['admin.js', 'admin.css', 'swfObject.js']
```
Or, you can opt to precompile all assets with something like this:
```ruby
-# config/application.rb
-config.assets.precompile << Proc.new do |path|
+# config/initializers/assets.rb
+Rails.application.config.assets.precompile << Proc.new do |path|
if path =~ /\.(css|js)\z/
full_path = Rails.application.assets.resolve(path).to_path
app_assets_path = Rails.root.join('app', 'assets').to_path
View
4 railties/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Move configuration of asset precompile list and version to an initializer.
+
+ *Matthew Draper*
+
* Do not set the Rails environment to test by default when using test_unit Railtie.
*Konstantin Shabanov*
View
6 railties/lib/rails/generators/rails/app/app_generator.rb
@@ -231,6 +231,12 @@ def delete_js_folder_skipping_javascript
end
end
+ def delete_assets_initializer_skipping_sprockets
+ if options[:skip_sprockets]
+ remove_file 'config/initializers/assets.rb'
+ end
+ end
+
def finish_template
build(:leftovers)
end
View
7 railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -33,12 +33,7 @@ Rails.application.configure do
# Generate digests for assets URLs.
config.assets.digest = true
- # Version of your assets, change this if you want to expire all your assets.
- config.assets.version = '1.0'
-
- # Precompile additional assets.
- # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
- # config.assets.precompile += %w( search.js )
+ # `config.assets.precompile` has moved to config/initializers/assets.rb
<%- end -%>
# Specifies the header that your server uses for sending files.
View
8 railties/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
+# Rails.application.config.assets.precompile += %w( search.js )
View
2  railties/test/generators/app_generator_test.rb
@@ -237,6 +237,7 @@ def test_generator_if_skip_action_view_is_given
def test_generator_if_skip_sprockets_is_given
run_generator [destination_root, "--skip-sprockets"]
+ assert_no_file "config/initializers/assets.rb"
assert_file "config/application.rb" do |content|
assert_match(/#\s+require\s+["']sprockets\/railtie["']/, content)
end
@@ -252,7 +253,6 @@ def test_generator_if_skip_sprockets_is_given
assert_no_match(/config\.assets\.digest = true/, content)
assert_no_match(/config\.assets\.js_compressor = :uglifier/, content)
assert_no_match(/config\.assets\.css_compressor = :sass/, content)
- assert_no_match(/config\.assets\.version = '1\.0'/, content)
end
end

1 comment on commit f166f1d

@Fudoshiki

Asset filtered out and will not be served: add Rails.application.config.assets.precompile += %w( static/home.css ) to config/initializers/assets.rb and restart your server

Showing /app/views/static/home.html.haml where line #4 raised:

Asset filtered out and will not be served: add Rails.application.config.assets.precompile += %w( static/home.css ) to config/initializers/assets.rb and restart your server

= content_for :content do
front page-home no-sidebars

content_for :head do = stylesheet_link_tag 'static/home', 'data-turbolinks-track' => true
latest rails 4.2.0 alpha from git

Please sign in to comment.
Something went wrong with that request. Please try again.