I am trying to create separate folders for keeping the assets related to backend and frontend. I planned the following folder structure: app/assets/dashboard/javascripts
instead of the usual one app/assets/javascripts
.
Backend is served via app/views/layouts/dashboard.html.erb
, and includes the assets in the following way:
<%= stylesheet_link_tag 'dashboard/dashboard', params[:controller], media: 'all' %>
<%= javascript_include_tag 'dashboard/dashboard', params[:controller] %>
Front end is served via app/views/layouts/application.html.erb
, and includes the assets in the following way:
<%= stylesheet_link_tag 'store/application', params[:controller], media: 'all' %>
<%= javascript_include_tag 'store/application', params[:controller] %>
I am not sure that what is the correct way to include the assets in this way, and hence getting 404 not found
error for http://dashboard.localhost.com:3000/javascripts/dashboard/javascripts/dashboard.js in the console
I've also tried changing the scripts path to <%= javascript_include_tag 'store/javascripts/application', params[:controller] %>
, but it doesn't work either. Also tried adding the following piece of code mentioned here to application.rb, but it didn't work either:
Dir.glob("#{Rails.root}/app/assets/**/").each do |path|
config.assets.paths << path
end
With these settings the paths populated in the console are as follows:
[9] pry(main)> Rails.application.config.assets.paths
=> ["/home/vipin8169/projectRoot/inmonarch_website/app/assets/images",
"/home/vipin8169/projectRoot/xyz/app/assets/javascripts",
"/home/vipin8169/projectRoot/xyz/app/assets/stylesheets",
"/home/vipin8169/projectRoot/xyz/vendor/assets/javascripts",
"/home/vipin8169/projectRoot/xyz/vendor/assets/stylesheets",
"/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/jquery-rails-4.1.0/vendor/assets/javascripts",
"/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/coffee-rails-4.1.1/lib/assets/javascripts",
"/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/react-rails-1.6.2/lib/assets/react-source/development-with-addons",
"/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/react-rails-1.6.2/lib/assets/javascripts/",
"/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/bootstrap-sass-3.3.6/assets/stylesheets",
"/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/bootstrap-sass-3.3.6/assets/javascripts",
"/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/bootstrap-sass-3.3.6/assets/fonts",
"/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/bootstrap-sass-3.3.6/assets/images"]
Is it supported in rails, altering the assets directory structure in this way?
In your application.rb file. add this
config.assets.enabled = true
config.assets.paths << Rails.root.join("app", "assets", "dashboard")
It would add this folder under the assets path. After that
stylesheet_link_tag 'dashboard', params[:controller], media: 'all'
would work.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments