rails routes using picnik with paperclip
I've been trying to get picnik to work with paperclip so I can resize and touch up images, however have had some difficulty so far.
I'm a bit confused over the routing, as I get an error:
Started POST "/products/3/photos/4" for 208.88.21.57 at Fri Dec 10 14:44:59 -0800 2010
ActionController::RoutingError (No route matches "/products/3/photos/4"):
This is when I try to pass the file back from picnik, however simply updating the image title on the same record using the exact same path seems to work fine and uses the exact same routing as above:
Started POST "/products/3/photos/4" for 69.149.172.21 at Fri Dec 10 14:52:29 -0800 2010
Processing by PhotosController#update as HTML
Parameters: {"photo"=>{"title"=>"Front"}, "commit"=>"Update Photo", "product_id"=>"3", "authenticity_token"=>"uZ3dV3BCSm7GvP39U51KCClx2P8gIWktyki/3rnpOIM=", "utf8"=>"\342\234\223", "id"=>"4"}
[paperclip] Saving attachments.
Redirected to http://leatherarts.heroku.com/products/3
Completed 302 Found in 17ms
What am I missing?
I ignored the authenticity token in the controller for the update action... btw
Picnik takes a basic params to submit back to by post, my line looks like this:
<%= link_to "Edit or Crop", "http://www.picnik.com/service/?_import=img&img=#{@photo.data.url(:original)}&_export=#{url_for(product_photo_url(@product,@photo))}&_export_field=photos_attributes&_export_title=SaveIt&_apikey=617c5c06600b6c21ebf0bc91eafbbae5" %>
Photo Model
has_attached_file :data,
:storage => 's3',
:s3_credentials => "#{RAILS_ROOT}/config/s3_credentials.yml",
:bucket => 'leatherarts.com',
:s3_host_alias => 'leatherarts.com.s3.amazonaws.com',
:url => ':s3_alias_url',
:path => "images/products/:product_id/:style/:basename.:extension",
:styles => { :thumb => "60x60#", :small => "200x200>", :medium => "400x400>", :large => "1000x1000>" },
:default_style => :original,
:default_url => 'http://leatherarts.com.s3.amazonaws.com/images/records/m1.png',
:s3_headers => { 'Expires' => 2.months.from_now.httpdate }
validates_attachment_presence :data
validates_attachment_size :data, :less_than => 10.megabytes
validates_attachment_content_type :data, :content_type => ['image/jpeg','image/gif','image/png']
UPDATE:
I got past the first problem with a specified PUT in a new route:
match 'products/:product_id/photos/:id/picnik' => 'photos#picnik', :as => :picnik
but still can't quite get it to all fall together. It seems to work and save, but it never saves the updated image.
I added this action in my photo controller
def picnik
@product = Product.find(params[:product_id])
@photo = Photo.find(params[:id])
@photo.data(params[:data])
if @photo.save
flash[:notice] = "Successfully updated photo."
redirect_to product_path(@product)
else
render :action => 'edit'
end
end
And according to the log it seems to do what it should:
Started POST "/products/10/photos/25/picnik" for 208.88.21.59 at Sat Dec 11 08:09:32 -0800 2010
Processing by PhotosController#picnik as HTML
Parameters: {"data"=>#<File:/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/RackMultipart20101211-7501-1tdkwuq-0>, "product_id"=>"10", "id"=>"25"}
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "x60" -crop "60x60+15+0" +repage '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-42lphg-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "1000x1000>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-1nskgrl-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_8开发者_开发百科8c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "400x400>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-fpe5rc-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "200x200>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-v5e99x-0' 2>/dev/null
[paperclip] saving images/products/10/original/DSC_0212.JPG
[paperclip] saving images/products/10/etsy/DSC_0212.JPG
[paperclip] saving images/products/10/thumb/DSC_0212.JPG
[paperclip] saving images/products/10/medium/DSC_0212.JPG
[paperclip] saving images/products/10/small/DSC_0212.JPG
[paperclip] Saving attachments.
Redirected to http://leatherarts.heroku.com/products/10
Completed 302 Found in 1632ms
But it's always the same image as before, with no new adjustments from picnik? I thought maybe it was the S3 Caching, but I created a new size category and it created it with the old image just the same.
精彩评论