I have app/assets/index.html.erb
containing <%= 'Hello world!' %>
, and added require "sprockets/railtie"
to config/application.rb
but when I run rake assets:precompile
(RAILS_ENV=development
) public/assets
stays empty.
What am I missing?
I am also using webpacker
and did not use sprockets
initially.
Asked
Active
Viewed 1,391 times
2

Jasper
- 1,971
- 19
- 34
-
1What do you expect in `public/assets` after assets:precompile? – QNester Mar 31 '19 at 09:41
-
I would expect index.html incl. "Hello world!". I had a typo: template is in `app/assets/index.html.erb` – Jasper Mar 31 '19 at 10:04
1 Answers
3
Views are not assets. Your view templates (erb, slim and etc.) will be compiled and rendered each time when rails process HTTP request. Read more about Rails views here.
Assets includes only css, js, fonts, images and etc. If you have no any assets files in assets folder then "rake assets:precompile" will do nothing. More about assets pipeline here.
UPD. May be this solution helps for you.
UPD2.
- I create file
assets/html/index.html.erb
with <%= "Hello, world!"%>. - I add follow line to my
config/application.rb
:
config.assets.precompile = ['*.js', '*.css', '*.html.erb']
- I add follow line to my manifest.js
//= link_directory ../html .html
- I run
rake assets:precompile
and see:
...
I, [2019-03-31T13:56:28.979563 #50803] INFO -- : Writing rails_app/public/assets/index-f4e7c3b6ac0beff671efa8cf84639011c06e58ca53a78d83f36107316cec125f.html
I, [2019-03-31T13:56:28.979832 #50803] INFO -- : Writing rails_app/public/assets/index-f4e7c3b6ac0beff671efa8cf84639011c06e58ca53a78d83f36107316cec125f.html.gz
...
- I open compiled file and see "Hello, world"

Matilda Smeds
- 1,384
- 11
- 18

QNester
- 463
- 4
- 9
-
I do not think that is correct. Sprockets should precompile erb too. I do not need to render all views dynamically - only those who change. – Jasper Mar 31 '19 at 10:15
-
@Jasper Yes, sprockets can precomplie erb, but this erb is not for views. You can use erb in css: https://guides.rubyonrails.org/asset_pipeline.html#css-and-erb or in js: https://guides.rubyonrails.org/asset_pipeline.html#javascript-coffeescript-and-erb . If you find way to compile html views to static files - give me know pls :) – QNester Mar 31 '19 at 10:25
-
1You should be able to configure precompiling whatever you want, I just don't know, how. – Jasper Mar 31 '19 at 10:47
-
sadly that is not working for me. I am pretty sure that is resulting from me having removed `sprockets` initially and added it manually and am now missing some important config. Where else do you reference `manifest.js` in your code? – Jasper Mar 31 '19 at 19:34
-
1@Jasper Manifest js required for sprocket 4. More: https://github.com/rails/sprockets/blob/master/UPGRADING.md#manifestjs – QNester Mar 31 '19 at 20:06