Generic Rails XML response to successful AJAX action? -


i think should easy syntax question, i'm not sure if approach correct. i'm using paperclip accept file upload flash. action creates object , saves upload, when tries generate xml response default xml generator think chokes trying include paperclip attachment in xml file. rails shows 406 error , flash throws i/o error.

i found a resource on embedding paperclip attachments in xml total overkill. flash needs success or failure message. like:

def jpg_stream   @photo = photo.new(:name => params[:name], :uploaded => time.now)   @photo.image = params[:image]   respond_to |format|     if @photo.save       format.xml  { "<success/>" }     else        format.xml  { render :xml => @photo.errors, :status => :unprocessable_entity }     end   end end 

what should line be?

format.xml  { "<success/>" } 

edit

this error stack trace. think rails has no problems returning whatever generated, 406 error means browser/flash not accept response.

started post "/generate_jpg" 127.0.0.1 @ 2011-01-25 12:59:24 -0700   processing photoscontroller#jpg_stream html   parameters: {"name"=>"test snapshot", "stream_id"=>"1", "filename"=>"this.jpg",     "image"=>#<actiondispatch:: http::uploadedfile:... [paperclip] identify -format %wx%h "c:/users/sam/appdata/local/temp/stream20110125-4048-zqbu60.jpg[0]" 2>nul   ←[1m←[35marel (1.0ms)←[0m  insert "photos" ("name", "description", "stream_id", "created_at", "updated_at", "image_file_name", "image_content_type", "image_file_size", "image_updated_at") values ('test snapshot', '2011-01-25 19:59:24.630999', 1, '2011-01-25 19:59:24.687002', '2011-01-25 19:59:24.687002', 'this.jpg', 'application/octet-stream', 12251, '2011-01-25 19:59:24.651000') [paperclip] saving attachments. [paperclip] saving .../system/images/86/original/this.jpg completed 406 not acceptable in 108ms 

i try simpler version first: render :xml => "<success/>". i.e., drop respond_to completely, leave

if @photo.save   render :xml => "<success/>" else    render :xml => @photo.errors, :status => :unprocessable_entity end 

i'm not sure nuances of respond_to (don't use myself), doing format.xml { "<success/>" } might require erb template you.

including error stacktrace nice too.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -