我正在使用 padrino 建立一个站点。我使用回形针将徽标上传到其中一个模型。我遇到的问题是 Paperclip 不保存附件,但也没有抛出任何错误。我认为传递给控制器的参数类型不正确,因为它params[:logo]
是一个散列,应该是某种文件类型?我怎样才能让回形针保存参数中传递的附件?
该模型:
class Charity < ActiveRecord::Base
include Paperclip::Glue
attr_accessible :name, :description, :logo
has_attached_file :logo, path: "/public/:attachment/:id/:basename.:extension"
end
徽标在控制器中设置如下:
post :create do
@charity = Charity.new(params[:charity])
if @charity.save!
flash[:notice] = 'Charity was successfully created.'
redirect url(:charities, :edit, id: @charity.id)
else
render 'charities/new'
end
end
将参数传递给控制器的表单如下所示(为简洁起见,省略了部分):
- form_for :charity, url(:charities, :create), multipart: true, class: :form do |f|
(...)
.group
==f.label :logo
==f.error_message_on :logo
==f.file_field :logo
(...)
我正在使用 Paperclip 2.7.0 和 Padrino 0.10.7。我还根据Using Paperclip with Padrino将此添加到 boot.rb :
Padrino.before_load do
File.send(:include, Paperclip::Upfile)
Paperclip.options[:logger] = Padrino.logger
Paperclip.options[:command_path] = "/usr/local/bin"
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, Paperclip::Schema)
ActiveRecord::ConnectionAdapters::Table.send(:include, Paperclip::Schema)
ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, Paperclip::Schema)
end