ruby-on-rails - ActiveStorage::InvariableError 使用 Mini Magick
问题描述
<%= image_tag @supply.supply_photo.variant(resize: "400x400") %>
这就是我的看法。@supply.supply_photo 适用于原始未调整大小的图像。我的图像是 webp ......我把它变成了具有相同结果的 jpg。我觉得我错过了一些简单的东西,但可以弄清楚我错过了什么。
我得到的错误是 ActiveStorage::InvariableError
我的日志显示
Started PUT "/__web_console/repl_sessions/cbaf86fd1070dd817c45101a6cf549f0" for ::1 at 2020-08-09 19:21:08 -0700
Started PUT "/__web_console/repl_sessions/cbaf86fd1070dd817c45101a6cf549f0" for ::1 at 2020-08-09 19:21:09 -0700
Started GET "/supplies/1" for ::1 at 2020-08-09 19:21:57 -0700
Processing by SuppliesController#show as HTML
Parameters: {"id"=>"1"}
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 2], ["LIMIT", 1]]
↳ app/controllers/concerns/set_current_request_details.rb:11:in `block (2 levels) in <module:SetCurrentRequestDetails>'
Account Load (0.8ms) SELECT "accounts".* FROM "accounts" INNER JOIN "account_users" ON "accounts"."id" = "account_users"."account_id" WHERE "account_users"."user_id" = $1 AND "accounts"."id" IS NULL LIMIT $2 [["user_id", 2], ["LIMIT", 1]]
↳ app/controllers/concerns/set_current_request_details.rb:24:in `block (2 levels) in <module:SetCurrentRequestDetails>'
Account Load (0.8ms) SELECT "accounts".* FROM "accounts" INNER JOIN "account_users" ON "accounts"."id" = "account_users"."account_id" WHERE "account_users"."user_id" = $1 ORDER BY "accounts"."created_at" ASC LIMIT $2 [["user_id", 2], ["LIMIT", 1]]
↳ app/controllers/concerns/set_current_request_details.rb:29:in `block (2 levels) in <module:SetCurrentRequestDetails>'
Supply Load (0.5ms) SELECT "supplies".* FROM "supplies" WHERE "supplies"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/supplies_controller.rb:51:in `set_supply'
Rendering supplies/show.html.erb within layouts/application
ActiveStorage::Attachment Load (0.4ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4 [["record_id", 1], ["record_type", "Supply"], ["name", "supply_photo"], ["LIMIT", 1]]
↳ app/views/supplies/show.html.erb:17
ActiveStorage::Blob Load (0.4ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 3], ["LIMIT", 1]]
↳ app/views/supplies/show.html.erb:17
Rendered supplies/show.html.erb within layouts/application (Duration: 7.3ms | Allocations: 2886)
Completed 500 Internal Server Error in 25ms (ActiveRecord: 3.6ms | Allocations: 6842)
ActionView::Template::Error (ActiveStorage::InvariableError):
14: <h5>Url</h5>
15: <%= @supply.url %>
16: </div>
17: <%= image_tag @supply.supply_photo.variant(resize_to_limit: "400x400") %>
18: </div>
19: </div>
20: </div>
app/views/supplies/show.html.erb:17
解决方案
这解决了我的问题
<%= image_tag @supply.supply_photo.variant(resize_to_limit: [400, 400]) %>
推荐阅读
- c++ - 重新制作所有标志变量为真
- python - Python Websocket 2-Way 通信
- python - Td Ameritrade Api 为历史 API 调用返回空 json 响应
- laravel - 声明抽象或实现其余方法
- asp.net-core - 如何在 ASP.NET Core 3.0 Identity 中配置 Twitter 外部身份验证
- python-3.x - 如何发送包含扩展查询的 graphQL 查询?
- craftcms - Craft CMS 返回错误的前端表单:请求缺少所需的正文参数
- r - R Shiny - 如何使用操作按钮在两个不同的图之间切换
- java - Java DAO 模式 - 在不使用多个类的情况下分离数据库通信责任
- python - 有什么方法可以抑制打印调用的输出?