I am building a site using padrino. I use paperclip for uploading logos to one of the models. The problem I am experiencing is that Paperclip does not save the attachment, but also does not throw any errors. I think that the parameters passed to the controller are of incorrect type, as the params[:logo]
is a hash and should probably be a some kind of a file type? How can I make Paperclip save the attachments passed in the parameters?
The model:
class Charity < ActiveRecord::Base
include Paperclip::Glue
attr_accessible :name, :description, :logo
has_attached_file :logo, path: "/public/:attachment/:id/:basename.:extension"
end
The logo is set in the controller like so:
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
The form passing the parameters to the controller looks like this (parts omitted for brevity):
- 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
(...)
I am using Paperclip 2.7.0 and Padrino 0.10.7. I also have added this to boot.rb as per Using Paperclip with Padrino :
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