【发布时间】:2021-01-04 18:51:50
【问题描述】:
在 rails 6 中使用 Paperclip 6.1.0 我收到此错误:
Paperclip::AdapterRegistry::NoHandlerError (未找到“logo.jpg”的处理程序):
在我的模型中,我有:
class Movie < ApplicationRecord
has_many :screens
has_many :tickets
has_attached_file :blob, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
# Validate the attached image is image/jpg, image/png, etc
validates_attachment_content_type :blob, :content_type => /\Aimage\/.*\Z/
end
异常发生在:
def create
@movie = Movie.new(movie_params)
if @movie.save
redirect_to @movie, notice: 'Movie was successfully created.'
else
带参数:
Parameters:
{"authenticity_token"=>"fzm4JrC/eGQsDUS04w52lfI7B5hC6agpSRtyn+4BSayWxRt1RG/lZDNypxxWVmcSZfaW6+HQ+auNJm7p43p/LQ==",
"movie"=>{"title"=>"test", "description"=>"345", "movie_length"=>"4r", "age_limit"=>"345", "price"=>"345", "category"=>"345", "blob"=>"Screen Shot 2020-12-30 at 10.24.49.png"},
"commit"=>"Create Movie"}
_form.html.erb:
<%= form_for @movie do |f|%>
<%= form_for @movie, html: { multipart: true } do |f|%>
<div class="form-group">
<% if @movie.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@movie.errors.count, "error") %> prohibited this movie from being saved:</h2>
<ul>
<% @movie.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%# <div class="field"> %>
<%= f.label :title %><br>
<%= f.text_field :title, class: "form-control", placeholder: "Title" %>
</div>
<div class="field">
<%= f.label :blob %><br>
<%= f.text_field :blob, class: "form-control", placeholder: "blob" %>
</div>
<div class="actions">
<%= f.submit %>
<%# f.submit will automatically give it a create or update button %>
</div>
<% end %>
<% end %>
有人知道怎么回事吗?
【问题讨论】:
-
blob应该是电影的预览图像吗?这是一个非常奇怪的名字选择。 -
是的,我可以改变它。但我想这不是问题?
-
不,问题很可能是您发送常规表单数据而不是多部分。参数应包含
ActionDispatch::Http::UploadedFile的实例,而不仅仅是字符串。我猜这是通过表单提交(而不是测试)发送的?可以添加表格吗? -
@max 我已经添加了表单。
标签: ruby-on-rails ruby rubygems paperclip