Erb
preprocessor, where the necessary helper <%= asset_path(path/to/template.html) %>
will be availableapp/assets/webapp/
. Let us configure our application so that it picks up templates *.html.slim
from our directory with templates: # config/application.rb config.assets.paths << Rails.root.join('app', 'assets', 'webapp') # config/initizlizers/assets_engine.rb Rails.application.assets.register_engine('.slim', Slim::Template) # config/environments/production.rb config.assets.precompile += ['*.html']
app/assets/webapp/rubrics/edit.html.slim
and want to access it from JavaScript. We cannot go to /assets/rubrics/edit.html
, because there will be no such file in the production environment, but something will be /assets/rubrics/edit-5eb3bb250d5300736006c8944e436e3f.html
. The correspondence table between the logical path rubrics/edit.html
and the full rubrics/edit.html
lies in the manifest file that is automatically generated. But using it is not always justified, it at least contains a lot of redundant data.js_assets
solves the problem of creating a matching table for files that fall under a particular mask. // app/assets/javascripts/application.js //= require app_assets
window.project_assets
. The helper asset_path
method takes as an argument the logical path to the required file and returns the relative path from the root, taking into account the environment. var path = asset_path('rubrics/edit.html') // the function will return for development: // /assets/rubrics/edit.html // and for production // /assets/rubrics/edit-5eb3bb250d5300736006c8944e436e3f.html
JsAssets::List.exclude = ["application.js"] JsAssets::List.allow = ["*.html"]
initializers
.Source: https://habr.com/ru/post/194968/
All Articles