def confirm_invite_new_tutor
redirect_with_msg = false
@game_school = GameSchool.find(params[:id])
existing_user_emails = params[:all_emails][:existing_user] || []
new_users = params[:param_game_school][:game_school_invites_attributes]
if existing_user_emails.present?
existing_user_emails.each do |existing_user|
// some code
end
redirect_with_msg = true
end
if new_users.present?
if @game_school.update_attributes(params[:param_game_school])
redirect_with_msg = true
else
render :invite_tutor_form
end
end
if redirect_with_msg
redirect_to @game_school, notice: "daw"
else
redirect_to @game_school
end
end
如果我执行此,我得到错误的redirect_to时与返回渲染
渲染和/或重定向在这次行动被称为多次。请注意,您只能调用渲染或重定向,并且每次最多只能调用一次。另外请注意,重定向和呈现都不会终止该动作的执行,因此如果您想在重定向后退出动作,则需要执行诸如“redirect_to(...)并返回”之类的操作。
如果我使用返回它带我到其他页面,甚至没有显示flash msg。 如何解决这个问题?
redirect_to xyz && return怎么样? – Lee 2014-04-05 10:10:40
在优先级上,'和'和'&&'(lol)在Ruby中有两个非常不同的含义(请参阅http://ruby-doc.org/core-2.3.0/doc/syntax/precedence_rdoc.html)。在这种情况下,你应该使用'和'。这也是该主题的另一个有趣资源:http://devblog.avdi.org/2014/08/26/how-to-use-rubys-english-andor-operators-without-going-nuts/ – lucke84 2016-03-17 11:20:05