ruby on rails - ruby_filemagic uploads in AJAX form, not otherwise -
i'm updating project uses ruby_filemagic upload images. there ajax form in iframe works, when transport code form, apparently identically structured (eg multipart, referring same object, in case @listing), throws error.
why case? there behaviour in ajax environment
the failing form tag looks :
<form action="/listings/add_description" class="edit_listing" enctype="multipart/form-data" id="edit_listing_26" method="post" onsubmit="return validateform(this,'listing_description');"> <div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="2vyjp37ff1adoob6zdets4frdxwgngnqqstb+honwu0=" />
while 1 works looks :
<form target="imageupload" method="post" id="new_listing" enctype="multipart/form-data" class="new_listing" action="/listings"> <div style="margin: 0pt; padding: 0pt; display: inline;"><input type="hidden" value="2vyjp37ff1adoob6zdets4frdxwgngnqqstb+honwu0=" name="authenticity_token"></div>
a successful upload (from second form looks :
processing listingscontroller#create (for 12.13.14.15 @ 2011-02-09 12:40:03) [post] parameters: {"commit"=>"create", "action"=>"create", "authenticity_token"=>"2vyjp37ff1adoob6zdets4frdxwgngnqqstb+honwu0=", "listing"=>{"end_date(3i)"=>"9", "discount_percent"=>"", "name"=>"test", "thumbnail"=>#<file:/var/folders/oo/oooj578khdy3igrantailu+++tm/-tmp-/rackmultipart20110209-5842-ipfdzh-0>, "start_date_text"=>"now", "category_id"=>"22", "regular_price"=>"100", "description"=>"test", "end_date(1i)"=>"2011", "end_date(2i)"=>"2", "sale_price"=>"30"}, "controller"=>"listings"}
while failed 1 (from non-ajax, first form looks follows. file in /tmp being created, 1 in /var not :
processing listingscontroller#add_description (for 12.13.14.15 @ 2011-02-09 12:41:39) [put] parameters: {"commit"=>"next -- set dates", "action"=>"add_description", "_method"=>"put", "authenticity_token"=>"2vyjp37ff1adoob6zdets4frdxwgngnqqstb+honwu0=", "listing"=>{"thumbnail"=>#<file:/var/folders/oo/oooj578khdy3igrantailu+++tm/-tmp-/rackmultipart20110209-5842-1k0wmd3-0>, "description"=>"description"}, "controller"=>"listings"} city load (0.4ms) select * "cities" ("cities"."id" = 18996) found new listing errno::enoent (no such file or directory - /tmp/2c33a5f0-1684-012e-ab73-00254bb57590): /opt/local/lib/ruby/1.8/fileutils.rb:1299:in `unlink' /opt/local/lib/ruby/1.8/fileutils.rb:1299:in `remove_file' /opt/local/lib/ruby/1.8/fileutils.rb:1304:in `platform_support' /opt/local/lib/ruby/1.8/fileutils.rb:1298:in `remove_file' /opt/local/lib/ruby/1.8/fileutils.rb:772:in `remove_file' /opt/local/lib/ruby/1.8/fileutils.rb:550:in `rm' /opt/local/lib/ruby/1.8/fileutils.rb:549:in `each' /opt/local/lib/ruby/1.8/fileutils.rb:549:in `rm' app/controllers/listings_controller.rb:47:in `check_listing_exists'
update : requested, here's controller actions: first, operating one, create :
def create @listing = listing.new(params[:listing]) @listing.merchant = merchant.find(current_merchant) responds_to_parent if @listing.save render :update |page| page.replace_html 'formview', :inline => "<div>listing '#{@listing.name}' created.</div>" page['formview'].setstyle('overflow' => 'auto') page.delay(2) page.visual_effect(:toggle_appear, 'formview', :duration => 0.2) end end else render :update |page| page.replace_html 'formview', :partial => 'new' end end end end
now, 1 fails :
def add_description unless @listing.save || session["skip_validation"] session["skip_validation"] = true redirect_to :back return end @listing.current_step_index= session["current_step_index"] = 2 @previous_stages = ["pre_listing","listing_comment"] @listing_partial = "complete_listing" render :partial => "listings", :layout => "application" end
i should mention action "add_description" working before, when there no file upload html in form, there no validations image thumnail, , html in form copied directly working form...
Comments
Post a Comment