Amin Salahuddin
2006-Mar-27 03:59 UTC
[Rails] file column inserts wrong file url field into database
Hello, ive set up file column like so Controller: def entry @entry = Entry.new(@params[:entry]) if @entry.save flash[:notice] = ''Product was successfully updated.'' else flash[:notice] = ''?'' end end Model: file_column :image View: <%= form_tag({:action=>''entry'', :id=> @entry }, :multipart => true)%> <%= file_column_field "entry", "image" %></p> <%= submit_tag ''entry'' %> <%= end_form_tag %> It seems like when the form is submitted it commits the hidden "image_temp" part of the multipart form instead of the "file" part. and this is what happens.: Parameters: {"commit"=>"Upload", "action"=>"entry", "controller"=>"entry", "entry"=>{"image_temp"=>"", "image"=>#<File:/tmp/CGI22011.1>}} SQL BEGIN SQL INSERT INTO entries (`entry`, `image`) VALUES(NULL, ''ihavebeenthinkingaboutyoual.gif'') SQL COMMIT so i end up with null value for my entry object. funny thing is if i put this in the entry view: <%=image_tag url_for_file_column "entry", "image" %> while submiting it from another .rhtml file, i get a correct path and the image shows up. acutally the image uploads perfectly but the url reference does not make it to the database. im new to rails so im not exactly sure how to tackle this. any help will be greatly appreciated. THANKS. -- Posted via http://www.ruby-forum.com/.