Note that there are some explanatory texts on larger screens.

plurals
  1. POPaperclip not called when uploading attachment, so attachment is not saved. Rails3 + uploadify
    primarykey
    data
    text
    <p>I have two different apps using paperclip. On the app that does not save attachment or call paperclip, i get this log when i upload an app</p> <pre><code>started POST "/users/1/uploads" for 127.0.0.1 at 2011-04-23 13:38:11 +0100 Processing by UploadsController#create as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"t2dRIH4FgOPnLRhpDK0x7iIfjB9Xj5rqkJRPCWZvJ14=", "upload"=&gt; {"document"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x2beeb08 @original_filename="Essay questions have various requirements.doc", @content_type="application/msword", @headers="Content-Disposition: form-data; name=\"upload[document]\"; filename=\"Essay questions have various requirements.doc\"\r\nContent-Type: application/msword\r\n", @tempfile=#&lt;File:C:/DOCUME~1/Ed/LOCALS~1/Temp/RackMultipart20110423-3980-ycq74p&gt;&gt;}, "commit"=&gt;"Upload", "user_id"=&gt;"1"} [1m[35mUser Load (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 [1m[36mUpload Load (0.0ms)[0m [1mSELECT "uploads".* FROM "uploads" WHERE ("uploads".uploadable_id = 1 AND "uploads".uploadable_type = 'User')[0m Rendered uploads/_uploadify.html.erb (15.6ms) Rendered uploads/_form.html.erb (31.2ms) Rendered uploads/new.html.erb within layouts/application (46.9ms) Completed 200 OK in 500ms (Views: 234.4ms | ActiveRecord: 0.0ms) </code></pre> <p>On the app where paperclip works fine, i get this log:</p> <pre><code>Started POST "/uploads" for 127.0.0.1 at Mon Apr 25 11:35:50 +0100 2011 Processing by UploadsController#create as JSON Parameters: {"_http_accept"=&gt;"application/javascript", "Filename"=&gt;"angels.txt", "folder"=&gt;"/users/", "authenticity_token"=&gt;"NVJj3ODIGuoc97wGvjWkez1YoN+SUDVtNJ+k80XdYXM=", "Upload"=&gt;"Submit Query", "user_id"=&gt;"1", "_uploadify_session"=&gt;"BAh7ByIQX2NzcmZfdG9rZW4iMU5WSmozT0RJR3VvYzk3d0d2aldrZXoxWW9OK1NVRFZ0TkorazgwWGRZWE09Ig9zZXNzaW9uX2lkIiU0ZDEyNzZkNzczNzk1MDdiMmQ4NWZmYTY5MDY4YTU0MQ==--7eb8c0ca249e2566998a0e68322a89d731fdb4ad", "Filedata"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x4958490 @content_type="application/octet-stream", @original_filename="angels.txt", @tempfile=#&lt;File:C:/DOCUME~1/Ed/LOCALS~1/Temp/RackMultipart20110425-4884-vyvdo8-0&gt;, @headers="Content-Disposition: form-data; name=\"Filedata\"; filename=\"angels.txt\"\r\nContent-Type: application/octet-stream\r\n"&gt;} [paperclip] identify -format %wx%h "C:/DOCUME~1/Ed/LOCALS~1 /Temp/stream20110425-4884-15he32x-0.txt[0]" 2&gt;NUL [paperclip] convert "C:/DOCUME~1/Ed/LOCALS~1/Temp/stream20110425-4884-15he32x-0.txt[0]" -resize "300x300&gt;" "C:/DOCUME~1/Ed/LOCALS~1/Temp/stream20110425-4884-15he32x-020110425-4884-r65fe6-0" 2&gt;NUL [paperclip] identify -format %wx%h "C:/DOCUME~1/Ed/LOCALS~1/Temp/stream20110425-4884-15he32x-0.txt[0]" 2&gt;NUL [paperclip] convert "C:/DOCUME~1/Ed/LOCALS~1/Temp/stream20110425-4884-15he32x-0.txt[0]" -resize "100x100&gt;" "C:/DOCUME~1/Ed/LOCALS~1/Temp/stream20110425-4884-15he32x-020110425-4884-1ttxfol-0" 2&gt;NUL [1m[36mAREL (15.6ms)[0m [1mINSERT INTO "uploads" ("user_id", "created_at", "photo_file_size", "photo_updated_at", "photo_content_type", "photo_file_name", "updated_at") VALUES (1, '2011-04-25 10:36:10.312500', 867, '2011-04-25 10:35:52.109375', 'text/plain', 'angels.txt', '2011-04-25 10:36:10.312500')[0m [paperclip] Saving attachments. [paperclip] saving C:/rails_project1/Uploadify-2/public/system/photos/2/medium/angels.txt [paperclip] saving C:/rails_project1/Uploadify-2/public/system/photos/2/thumb/angels.txt [paperclip] saving C:/rails_project1/Uploadify-2/public/system/photos/2/original/angels.txt Completed 200 OK in 19422ms (Views: 62.5ms | ActiveRecord: 15.6ms) </code></pre> <p>The only difference between the two is that the one not working is polymorphic model and the controller for the polymorphic model is below:</p> <pre><code>class UploadsController &lt; ApplicationController before_filter :find_parent before_filter :prepare_input_params #respond_to :html, :json, :js def index @uploads = Upload.all #@uploads = @parent.try(:uploads).try(:all) @upload = Upload.new #respond_with([@parent, @uploads]) end def new @upload = @parent.uploads.new end def create @upload = @parent.uploads.build(params[:upload]) if @upload.save flash[:notice] = "sucessfully saved upload" respond_to do |format| format.html {redirect_to [@parent, :uploads]} format.json {render :json =&gt; { :result =&gt; 'success', :upload =&gt; polymorphic_url([@parent,:uploads]) } } end else render :action =&gt; 'new' end end def edit @upload = Upload.find(params[:id]) end def show "puts @upload.inspect" @upload = @parent.uploads.find(params[:id]) @total_uploads = @parent.uploads.find(:all, :conditions =&gt; { :user_id =&gt; @upload.user.id}) end def update @upload = Upload.find(params[:id]) if @upload.update_attributes(params[:upload]) flash[:notice] = "Successfully updated document" redirect_to @upload else render :action =&gt; 'edit' end end def destroy @upload = Upload.find(params[:id]) @upload.destroy redirect_to([@parent, :upload]) end private def prepare_input_params params[:upload][:document] = params[:Filedata] if params[:Filedata] end </code></pre> <p>end</p> <p>Here is the gist file with the form partial and uploadify bit: <a href="https://gist.github.com/940960" rel="nofollow">https://gist.github.com/940960</a>. The form has :html => { :multipart => true }. </p> <p>Thanks for the help.</p> <p><strong>EDIT</strong>:</p> <p>It seems the problem is from the model, uploads.rb. When i comment out the section below: everything works, but i need to be able to use validations and specify path as i want to use S3. Anyhelp on how i can uncomment the code without the initial error of paperclip not saving happening again.</p> <pre><code>class Upload &lt; ActiveRecord::Base attr_accessible :document belongs_to :uploadable, :polymorphic =&gt; true has_attached_file :document, :styles =&gt; { :small =&gt; "150x150&gt;",:thumb =&gt; "100x100&gt;" } =begin :url =&gt; "/uploads/:id/:style/:basename.:extension", :path =&gt; ":rails.root/public/:uploads/:id/:style/:basement.:extension" validates_attachment_presence :document validates_attachment_size :document, :less_than =&gt; 5.megabytes validates_attachment_content_type :document, :content_type =&gt; ['application/octet-stream','image/jpeg','image/gif', 'image/png', 'image/pdf', 'image/doc', 'video/x-m4v', 'video/quicktime','application/x-shockwave-flash', 'audio/mpeg', 'video/mpeg', 'application/pdf','application/msword'] =end </code></pre> <p>end</p> <p><strong>Update</strong>:</p> <p>I think the main problem seem to be that why attaching a new file, paperclip, somehow starts calling <strong>SELECT "uploads".*'from "uploads"</strong> instead of calling <strong>INSERT INTO 'uploads'</strong>, that is <strong>controller#create action</strong> shown higher up seems to be calling SELECT, whenever ever i provide :url and :path options to paperclip has_attached_file method. See the log below:</p> <pre><code>Processing by UploadsController#create as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"Azxzi09R7NU7+jxj+lxHFGfs+qw7D6b7yRKegRjRQMc=", "upload"=&gt; {"document"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x2994ff0 @original_filename="al night verses.txt", @content_type="text/plain", @headers="Content-Disposition: form-data; name=\"upload[document]\"; filename=\"al night verses.txt\"\r\nContent-Type: text/plain\r\n", @tempfile=#&lt;File:C:/DOCUME~1/Ed/LOCALS~1 /Temp/RackMultipart20110505-3444-1rlpnr&gt;&gt;}, "commit"=&gt;"Upload", "user_id"=&gt;"1"} [1m[35mUser Load (0.0ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 [paperclip] C:\ImageMagick-6.6.3-Q16/identify -format %wx%h "C:/DOCUME~1/Ed/LOCALS~1 /Temp/stream20110505-3444-1cpnf87.txt[0]" [paperclip] C:\ImageMagick-6.6.3-Q16/convert "C:/DOCUME~1/Ed/LOCALS~1 /Temp/stream20110505-3444-1cpnf87.txt[0]" -resize "150x150&gt;" "C:/DOCUME~1/Ed/LOCALS~1 /Temp/stream20110505-3444-1cpnf8720110505-3444-1vnp5jx" [paperclip] C:\ImageMagick-6.6.3-Q16/identify -format %wx%h "C:/DOCUME~1/Ed/LOCALS~1 /Temp/stream20110505-3444-1cpnf87.txt[0]" [paperclip] C:\ImageMagick-6.6.3-Q16/convert "C:/DOCUME~1/Ed/LOCALS~1 /Temp/stream20110505-3444-1cpnf87.txt[0]" -resize "100x100&gt;" "C:/DOCUME~1/Ed/LOCALS~1 /Temp/stream20110505-3444-1cpnf8720110505-3444-1vyk9i" [1m[36mUpload Load (0.0ms)[0m [1mSELECT "uploads".* FROM "uploads" WHERE ("uploads".uploadable_id = 1 AND "uploads".uploadable_type = 'User')[0m Rendered uploads/_uploadify.html.erb (15.6ms) Rendered uploads/_form.html.erb (31.2ms) Rendered uploads/new.html.erb within layouts/application (62.5ms) </code></pre> <p><strong>Based on @CharlieMezak's request, here is the views/uploads/_form.html.erb</strong>:</p> <pre><code>&lt;%= debug @parent %&gt; &lt;%= render :partial =&gt; "uploads/uploadify" %&gt; &lt;/br&gt; &lt;%= form_for [parent, upload], :html =&gt; { :multipart =&gt; true } do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :document %&gt;&lt;br /&gt; &lt;%= f.file_field :document %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit "Upload"%&gt; &lt;/div&gt; </code></pre> <p><strong>views/uploads/new.html.erb</strong>:</p> <pre><code>&lt;%= render 'form', :parent =&gt; @parent, :upload =&gt; @upload %&gt; </code></pre> <p><strong>views/users/index.html.erb</strong>:</p> <pre><code>&lt;%= render "uploads/form", :parent =&gt; user, :upload =&gt; user.uploads.new %&gt; </code></pre> <p><strong>More Update</strong> :</p> <p>Like i mentioned, when i comment out the <strong>:styles, : :url and :path</strong> options from paperclips's **'has_many_attachment :document', the INSERT statement is called and though it saves the file, instead of displaying the attached file, it ends up displaying several parameters like authenticity tokens etc on the website as shown below:</p> <pre><code>attributes: id: 1 email: xyz@yahoo.com encrypted_password: $2a$10$HiksbkRXDtcXiJyUIRj password_salt: $2a$10$HiksbkRXD reset_password_token: !!null remember_token: !!null remember_created_at: !!null sign_in_count: 3 current_sign_in_at: '2011-04-25 18:57:27.078125' last_sign_in_at: '2011-04-25 09:25:31.406250' current_sign_in_ip: 127.0.0.1 last_sign_in_ip: 127.0.0.1 created_at: '2011-04-09 17:46:15.546875' updated_at: '2011-04-25 18:57:27.078125' changed_attributes: {} previously_changed: {} attributes_cache: {} marked_for_destruction: false destroyed: false readonly: false new_record: false </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload