ruby on rails 3 渲染json 406 Not Acceptable错误的解决办法

ruby on rails 3 渲染json 406 Not Acceptable错误的解决办法

如果用默认的写法
[ccn lang="ruby" tab_size="4" theme="blackboard" width="800" ]

respond_to do |format|
if @dl_image.update_attributes(params[:dl_image])
format.html { redirect_to(@dl_image, :notice => 'Dl image was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @dl_image.errors, :status => :unprocessable_entity }
end
end
[/ccn]
这样在浏览只有输入xxx.json才能返回json数据,如果这个方法是直接传给jquery等ajax方法的
就需要改成直接渲染json
[ccn lang="ruby" tab_size="4" theme="blackboard" width="800" ]

render :json => { :pic_path => "aaaaaaaaaaaa" + file_folder , :name => new_name }.to_json, :content_type => 'text/xml'
[/ccn]
这样浏览器就能正确解析