2016-03-14 84 views
1

我正在嘗試爲保留與後端和前端相關的資產創建單獨的文件夾。我計劃了以下文件夾結構:app/assets/dashboard/javascripts而不是通常的app/assets/javascripts在導軌上包含ruby中的自定義文件夾特定資產

enter image description here

後端經由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] %> 

我不確定以這種方式包含資產的正確方法是什麼,因此獲得404 not found錯誤控制檯中的http://dashboard.localhost.com:3000/javascripts/dashboard/javascripts/dashboard.js

我也嘗試將腳本路徑更改爲<%= 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/[email protected]/gems/jquery-rails-4.1.0/vendor/assets/javascripts", 
"/home/vipin8169/.rvm/gems/[email protected]/gems/coffee-rails-4.1.1/lib/assets/javascripts", 
"/home/vipin8169/.rvm/gems/[email protected]/gems/react-rails-1.6.2/lib/assets/react-source/development-with-addons", 
"/home/vipin8169/.rvm/gems/[email protected]/gems/react-rails-1.6.2/lib/assets/javascripts/", 
"/home/vipin8169/.rvm/gems/[email protected]/gems/bootstrap-sass-3.3.6/assets/stylesheets", 
"/home/vipin8169/.rvm/gems/[email protected]/gems/bootstrap-sass-3.3.6/assets/javascripts", 
"/home/vipin8169/.rvm/gems/[email protected]/gems/bootstrap-sass-3.3.6/assets/fonts", 
"/home/vipin8169/.rvm/gems/[email protected]/gems/bootstrap-sass-3.3.6/assets/images"] 

是否支持rails,以這種方式更改資產目錄結構?

回答

1

在你的application.rb文件中。添加此

config.assets.enabled =真

config.assets.paths < < Rails.root.join( 「應用程序」, 「資產」, 「儀表板」)

它會在資產路徑下添加此文件夾。這

stylesheet_link_tag '儀表盤' 後,則params [:控制器]媒體: '全部'

會工作。

+0

添加了這兩個:'config.assets.paths << Rails.root.join(「app」,「assets」,「dashboard」)''和'config.assets.paths << Rails.root.join(「應用程序「,」資產「,」商店「)',但仍然得到404的http://dashboard.localhost.com:3000/stylesheets/dashboard/dashboard.css – vipin8169

+0

你重新啓動服務器? –

+0

是的,我重新啓動 – vipin8169

相關問題