I'm currently converting a very small Rails application to Sinatra. This Rails app was relying on ActiveRecord + Paperclip + Amazon S3 for picture storage, and I have troubles making it work in Sinatra (but I believe it would be the same for any kind of Rack-based application), with ActiveRecord + Paperclip + Amazon S3 as well.
Here's what I have so far:
Gemfile:
gem 'paperclip'
gem 'paperclip-rack', require: 'paperclip/rack'
gem 'aws-sdk'
Model:
class Photo < ActiveRecord::Base
include Paperclip::Glue
has_attached_file :image,
:storage => :s3,
:s3_credentials => "config/s3.yml",
:bucket => 'mybucket',
:path => ':style/:photo_id.:extension',
:styles => {
:original => '1200x1200>',
:miniature => '80x80#',
:slideshow => 'x200'
}
end
View:
form method="post" action="/photos/add" enctype='multipart/form-data'
input type="file" name="image"
input#submit-button type="submit"
Route/Action:
post '/photos/add' do
photo = Photo.new
photo.image = params[:image]
#image[:tempfile] = params[:image][:tempfile],
#image[:filename] = params[:image][:filename],
#image[:content_type] = params[:image][:type],
#image[:size] = params[:image][:tempfile].size
photo.save
redirect "/"
end
And the error I'm getting when trying to upload something :
NoMethodError at /admin/photos/add
undefined method `descendants' for Paperclip::Validators::AttachmentFileNameValidator:Class
file: attachment.rb location: each line: 393
I've tried to play with the :image
param in my route (and manually assign each value to the field that was created by paperclip, see the commented lines) but it didn't seem to work any better. Any idea guys ? I'm stuck and have no clue where to start to get this to work.
Note: I've removed all validations and stuff so I even don't understand the error message I'm getting.