首页 > 解决方案 > Ruby on Rails / 资产管道为空

问题描述

我正在使用 Rails 5.2 我正在尝试访问图像的路径,如下所示:

<%=  image_path(@pin.image)%>

我在终端中收到以下错误消息。

我是不是忘了在 config.assets.paths 中设置一些东西?或链轮设置错误?

在 2018-07-18 20:53:06 +0900 (1.0ms) 开始 GET "/pins/2" for 127.0.0.1 SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC ↳ /Users/computer/.rvm/gems/ruby-2.4.0/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98 PinsController 处理#show as HTML 参数:{"id"=> "2"} 引脚负载 (0.2ms) 选择 "pins".* FROM "pins" WHERE "pins"."id" = ? 限制 ?[["id", 2], ["LIMIT", 1]] ↳ app/controllers/pins_controller.rb:67 在布局/应用程序中渲染 pin/show.html.erb ActiveStorage::Attachment Load (0.2ms) SELECT " active_storage_attachments".* FROM "active_storage_attachments" WHERE "

ActionView::Template::Error(资产“”不存在于资产管道中。):

  6: </p>
  7: 
  8: <%= image_tag(@pin.image) %>
  9: <%=  image_path(@pin.image)%>
 10: 
 11: 
 12: 

app/views/pins/show.html.erb:9:in `_app_views_pins_show_html_erb__253993838852336219_70195426237620'

标签: ruby-on-rails-5sprockets

解决方案


我刚刚通过使用解决了我的问题:

<%=  rails_blob_url(@pin.image)%>

这是正确的方法吗?


推荐阅读