【发布时间】:2021-10-28 08:50:00
【问题描述】:
根据文档,我将action_text/trix 添加到我的rails 应用程序中。当我更新内容时。它向我显示了以下错误。有什么想法吗?
Showing /home/dell/code/tm/app/views/active_storage/blobs/_blob.html.erb where line #3 raised:
Can't resolve image into URL: undefined method `to_model' for #<ActiveStorage::VariantWithRecord:0x0000559255e1be40 @blob=#<ActiveStorage::Blob id: 12, key: "n48e43looijem16cdq5d48sqhu4d", filename: "Screenshot from 2021-08-28 17-10-25.png", content_type: "image/png", metadata: {}, service_name: "local", byte_size: 93757, checksum: "up8PwkoYwf+Y6NTRJvbAUA==", created_at: "2021-08-29 12:13:04.912555000 +0800">, @variation=#<ActiveStorage::Variation:0x0000559255e248d8 @transformations={:format=>"png", :resize_to_limit=>[1024, 768]}>>
Did you mean? to_yaml
ActionView::Template::Error (Can't resolve image into URL: undefined method `to_model' for #<ActiveStorage::VariantWithRecord:0x0000559255e1be40 @blob=#<ActiveStorage::Blob id: 12, key: "n48e43looijem16cdq5d48sqhu4d", filename: "Screenshot from 2021-08-28 17-10-25.png", content_type: "image/png", metadata: {}, service_name: "local", byte_size: 93757, checksum: "up8PwkoYwf+Y6NTRJvbAUA==", created_at: "2021-08-29 12:13:04.912555000 +0800">, @variation=#<ActiveStorage::Variation:0x0000559255e248d8 @transformations={:format=>"png", :resize_to_limit=>[1024, 768]}>>
Did you mean? to_yaml):
1: <figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
2: <% if blob.representable? %>
3: <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
4: <% end %>
5:
6: <figcaption class="attachment__caption">
app/views/active_storage/blobs/_blob.html.erb:3
宝石文件:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.0.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.2'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
gem 'devise'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
# gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
gem 'pagy', '~> 3.5'
gem 'money-rails', '~>1.12'
gem "view_component", require: "view_component/engine"
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
gem 'metka', '~> 2.3.1'
gem 'ransack', '~> 2.4.2'
gem 'country_select', '~> 6.0'
gem 'rails-i18n', '~> 6.0.0'
我的模特:
class Page < ApplicationRecord
has_rich_text :body
end
以及迁移:
class CreatePages < ActiveRecord::Migration[6.1]
def change
create_table :pages do |t|
t.string :title
t.string :slug
t.timestamps
end
end
end
这里是视图:
<div class="row">
<div class="col-md-12">
<div class="mb-3">
<%= f.label :body, class: 'form-label required' %>
<%= f.rich_text_area :body %>
<%= display_error_messages(@resource, 'body') %>
</div>
</div>
</div>
根据文档,我没有将 body 列添加到 pages 表中。
任何想法?我错过了什么吗?
更新:
我将gem 'image_processing' 添加到Gemfile。但结果是一样的:(
更新 2:我还在我的 Ubuntu 中安装了 imagemagick。
更新 3:它不仅在 update 操作中有效。
【问题讨论】:
-
您找到解决方案了吗?
标签: ruby-on-rails ruby trix actiontext