[英]ActionController::RoutingError (No route matches [GET] “/assets/images/logo.png”):
[英]ActionController::RoutingError (No route matches [GET] "/assets/images
我正在嘗試在Rails應用程序中加載一些靜態頁面和文件(圖像,CSS和javascript)以進行測試。 但是沒有圖像加載,也沒有引導渲染。 在服務器上運行它(使用rails server
)之前,我嘗試過如下所示在Stackoverflow上查找的其他選項
使用命令rake assets:precompile
並使用'rake tmp:clear'或手動刪除tmp目錄中的內容
更改圖像標簽的HTML語法,以在資源目錄../../assets/images/hero-images/*.jpg
下打開不同的圖像,例如:
之前: <img src="../../assets/images/hero-images/abyssal_underlord_sb.png">
現在: <%= image_tag("../../assets/images/hero-images/abyssal_underlord_sb.png") %>
../..
基本上告訴我,我必須回到app
目錄才能訪問images文件夾,但仍然無法正常工作
RAILS_ENV=production bundle exec rake assets:precompile
但也沒有運氣。 更新 :
config
目錄中修復配置。 我在應用程序的development.rb
文件中有這行config.serve_static_assets = true
(甚至嘗試使用rake assets:precompiles
但仍然沒有運氣。 您可以通過兩種方式渲染位於assets/images
內部文件夾中的assets/images
。
1在application.rb
添加以下內容
config.assets.paths << Rails.root.join('app', 'assets', 'hero-images')
Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
config.assets.paths << path
end
直接訪問圖像
<img src="assets/hero-images/abyssal_underlord_sb.png">
<%= image_tag("abyssal_underlord_sb.png")%>
2.只需在文件名上方添加內部文件夾名。
<%= image_tag("hero-images/abyssal_underlord_sb.png")%>
請參閱此鏈接https://learn.co/lessons/images-and-the-asset-pipeline
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.