Reputation: 53
Sprockets::Rails::Helper::AssetNotFound in Webjinny::Frontend#index Showing /home/krapirastogi/webjinny/app/views/layouts/webjinny/default_theme.html.erb where line #15 raised:
The asset "default_theme/css/default.css" is not present in the asset pipeline. My view file in engine .. Default_theme.html.erb inside layouts/myengine/default_theme
<head>
<title>Default_theme</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!-- Mobile Metas -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<!-- Site Metas -->
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="author" content="" />
<%= stylesheet_link_tag 'default_theme/css/default', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_importmap_tags %>
</head>
The engine.rb file looks like this
module Webjinny
class Engine < ::Rails::Engine
isolate_namespace Webjinny
# Precompile specific assets
initializer 'webjinny.assets.precompile' do |app|
app.config.assets.precompile += %w( default_theme/css/default.css )
end
# Add custom asset paths
initializer 'webjinny.assets.paths' do |app|
app.config.assets.paths << Webjinny::Engine.root.join('app', 'apps', 'themes', 'default_theme', 'assets', 'css')
end
end
end
The location of the file is here--
webjinny/ app/ apps/ themes/ default_theme/ assets/ css/ default.css
How do I link it ? Where is the mistake ? How do you render stylesheets from a folder in a rails Engine ?
Upvotes: 2
Views: 88
Reputation: 29719
Add a new asset path, it can be anywhere you like:
initializer "webjinny.assets.paths" do |app|
app.config.assets.paths << root.join("app/apps/themes")
end
Precompile path is relative to your asset path:
initializer "webjinny.assets.precompile" do |app|
app.config.assets.precompile += %w(default_theme/assets/css/default.css)
end
Then reference what you're precompiling (relative to asset path):
<%= stylesheet_link_tag "default_theme/assets/css/default", media: "all", "data-turbolinks-track": "reload" %>
Upvotes: 0