How should one provide assets in an engine in Rails 3.1? Where should they be located and can they be included automatically?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The paths to the all the engines’ assets folders are automatically loaded.
The assets themselves are not loaded by default. This is understandable as the loading is done with
require_tree ., which loads all css/js from the current folder (i.e. the main application assets’ folder) but doesn’t say anything about the engines assets.The easy solution is to ask the user to require the js/css in application.js/css or wherever else it is needed. As the paths are loaded correctly, the user only need to specify the name of your asset (I’d recommend using the name of your engine). Example:
Appended to
main_app/app/assets/javascripts/application.js:If you have split your js in different files, your file
your_engine_name/app/assets/javascripts/your_engine_name.jscould have the following:This will load all js files in
your_engine_name/app/assets/javascripts/, as the “.” refers to the local folder (in this case the folder of your engine’s javascripts).Note that
ActionView::Helpers::AssetTagHelper.register_javascript_expansionappears not to have any effect whenconfig.use_sprocketsis set. I hope they’ll at least put a warning in that case.If you have a rake task to install your engine, then you could do the append to application.js.
Another way for the user to include it is to insert
<%= javascript_include_tag "your_engine_name" %>in the erb layout.I don’t think there is a way to have it inserted automatically