Welcome Guest | Login

act_as_attachment wierd failure

I am getting a weird error when trying to upload files using act_as_attachment. I think it's something incorrect with my configuration. I get this in the log

Processing NotesController#createupload (for *.*.*.* at 2007-05-26 19:59:16) [POST]
 Session ID: 98873ed2fff1d2d53cbbe7633ed34797
 Parameters: {"commit"=>"Create", "page_id"=>"2", "action"=>"createupload", "upload"=>{"uploaded_data"=>#<File:/tmp/CGI.12417.0>}, "controller"=>"notes"}


ActiveRecord::StatementInvalid (Mysql::Error: Column 'page_id' cannot be null: INSERT INTO uploads (`content_type`, `size`, `thumbnail`, `page_id`, `filename`, `height`, `parent_id`, `width`) VALUES('application/msword', 96256, NULL, NULL, 'bioremediation_paper.doc', NULL, NULL, NULL)):

any ideas where to look?

2007-05-26 08:07 PM

Hmm - so it looks like page_id is getting passed as a parameter but its not getting sent into the SQL call.  Can you paste the relevant code from your NotesController#createupload file  -- that will tell us more.  Essentially just triple check that page_id isn't in fact null.  

2007-05-27 01:29 AM

Good call. Pointed me to the problem. Here is what the function looked like in the controller. i'm sure there are better ways of doing it.
 def createupload
   @upload = Upload.create! params[:upload]
   Page.find(params[:page_id]).uploads << @upload
   redirect_to(:action => 'viewpage', :id => params[:page_id] )
 end

the problem was solved by changing
   @upload = Upload.create! params[:upload]  to
   @upload = Upload.new(params[:upload])
works like a charm!

2007-05-27 12:27 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!