我正在尝试创建单独的文件夹,以保持资产与后端和前端相关。我计划了以下文件夹结构:app/assets/dashboard/javascripts
而不是通常的app/assets/javascripts
。
后端通过app/views/layouts/dashboard.html.erb
投放,并按以下方式包含资产:
<%= stylesheet_link_tag 'dashboard/dashboard', params[:controller], media: 'all' %>
<%= javascript_include_tag 'dashboard/dashboard', params[:controller] %>
前端通过app/views/layouts/application.html.erb
投放,并按以下方式包含资产:
<%= stylesheet_link_tag 'store/application', params[:controller], media: 'all' %>
<%= javascript_include_tag 'store/application', params[:controller] %>
我不确定以这种方式包含资产的正确方法是什么,因此在控制台中http://dashboard.localhost.com:3000/javascripts/dashboard/javascripts/dashboard.js出现404 not found
错误
我还尝试将脚本路径更改为<%= javascript_include_tag 'store/javascripts/application', params[:controller] %>
,但它也无法正常工作。
还尝试将以下here提到的代码添加到application.rb,但它也没有工作:
Dir.glob("#{Rails.root}/app/assets/**/").each do |path|
config.assets.paths << path
end
使用这些设置,控制台中填充的路径如下:
[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"]
是否支持rails,以这种方式改变资产目录结构?
答案 0 :(得分:2)
在application.rb文件中。添加这个
config.assets.enabled = true
config.assets.paths&lt;&lt; Rails.root.join(&#34; app&#34;,&#34; assets&#34;,&#34; dashboard&#34;)
它会在资源路径下添加此文件夹。之后
stylesheet_link_tag&#39; dashboard&#39;,params [:controller],media:&#39; all&#39;
会起作用。