I'm using Rails 3.1 with Paperclip and looking for a way to implement jQuery-File-Upload.
I've a basic working setup by following the example:
blueimp jquery=file-upload
But when I introduced a nested attributes model where uploads are nested within post, it falls apart. The error given is "unknown attribute: picture". Understand that the uploads_attributes may have to be marshaled separately, particularly for picture params, from the query script to the controller. How do I go about specifying the params?
Request: http://localhost:3002/posts/3
Error:
ActiveRecord::UnknownAttributeError in PostsController#update
unknown attribute: picture
Rails.root: /Users/mjwong/workspace/testupload
Application Trace | Framework Trace | Full Trace
app/controllers/posts_controller.rb:63:in `block in update'
app/controllers/posts_controller.rb:62:in `update'
Request
Parameters:
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"1SYnIX+Y5PxM7PskzV/zocCJfh60tyGkUBdwu7OmNo8=",
"post"=>{"title"=>"test",
"content"=>"test",
"picture"=>#<ActionDispatch::Http::UploadedFile:0x007fe346dbeaf8 @original_filename="Alva 2.jpg",
@content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"post[picture]\"; filename=\"Alva 2.jpg\"\r\nContent-Type: image/jpeg\r\n",
@tempfile=#<File:/var/folders/_w/24l2jy1563d2qqh8w0x4qmgh0000gn/T/RackMultipart20111030-3671-10zn91c>>},
"commit"=>"Update Post",
"id"=>"3"}
Models:
class Post < ActiveRecord::Base
has_many :uploads, :dependent => :destroy
accepts_nested_attributes_for :uploads, :allow_destroy => true
end
class Upload < ActiveRecord::Base
belongs_to :post
has_attached_file :picture, :styles => {:thumb => "100x100#",
:small => "300x300>",
:large => "600x600>" },
:url => "/system/:class/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension"
validates_attachment_size :picture, :less_than => 500.kilobytes
validates_attachment_content_type :picture, :content_type => ['image/jpeg', 'image/png']
end
Controllers:
class HomeController < ApplicationController
def index
@upload = Upload.new
end
end