如何转换此response_to选项以使用Rails 3版本? [英] How to convert this respond_to options to use Rails 3 version?
本文介绍了如何转换此response_to选项以使用Rails 3版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
respond_to do |format|
if @user.save
format.js { render :nothing => true, :status => :ok, :location => @user }
else
format.js { render :json => @user.errors, :status => :unprocessable_entity }
end
end
我尝试过的所有选项(例如将respond_to :js
放在控制器的顶部等)都无法像这种方式那样起作用.
All options I've tried (like putting respond_to :js
at the top of controller, etc) don't quite work the way as in this.
推荐答案
Rails 3格式:
Rails 3 Format:
使用 respond_to :json和 respond_with (@ user)
Use respond_to :json and respond_with(@user)
respond_to :json # You can also add , :html, :xml etc.
def create
@user= User.new(params[:user])
#---For html flash
#if @user.save
# flash[:notice] = "Successfully created user."
#end
respond_with(@user)
end
# Also, add :remote => :true, :format => :json to the form.
这篇关于如何转换此response_to选项以使用Rails 3版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文