gpt4 book ai didi

ruby-on-rails-4 - 在 ruby​​ on rails 中包含自定义文件夹特定 Assets

转载 作者:行者123 更新时间:2023-12-02 01:27:57 25 4
gpt4 key购买 nike

我正在尝试创建单独的文件夹来保存与后端和前端相关的 Assets 。我计划了以下文件夹结构:app/assets/dashboard/javascripts而不是通常的 app/assets/javascripts .

enter image description here

后端通过 app/views/layouts/dashboard.html.erb 提供服务,并按以下方式包括 Assets :

<%= stylesheet_link_tag 'dashboard/dashboard', params[:controller], media: 'all' %>
<%= javascript_include_tag 'dashboard/dashboard', params[:controller] %>

前端通过 app/views/layouts/application.html.erb 提供服务,并按以下方式包括 Assets :
<%= stylesheet_link_tag 'store/application', params[:controller], media: 'all' %>
<%= javascript_include_tag 'store/application', params[:controller] %>

我不确定以这种方式包含 Assets 的正确方法是什么,因此得到 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/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 是否支持它,以这种方式改变 Assets 目录结构?

最佳答案

在您的 application.rb 文件中。添加这个

config.assets.enabled = true

config.assets.paths << Rails.root.join("app", "assets", "dashboard")



它会在 Assets 路径下添加这个文件夹。在那之后

stylesheet_link_tag 'dashboard', params[:controller], media: 'all'



会工作。

关于ruby-on-rails-4 - 在 ruby​​ on rails 中包含自定义文件夹特定 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35981571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com