呈现启动更新的操作 [英] Render the action that initiated update
问题描述
我有一个 SettingsController,其中包含操作 account 和 profile,还有一个 update,如下所示:
I have a SettingsController with actions account and profile, and also an update that looks like:
def update
@player = current_user
if @player.update_attributes(params[:player])
flash[:success] = "Profile updated."
redirect_to :back
else
@title = "Edit"
render
end
end
现在个人资料和帐户操作都有一个对应的视图,带有一个表单来编辑播放器模型的一些记录.
Now the profile and account actions each have a corresponding view, with a form to edit some records of the Player model.
当您尝试保存其中一种表单时,它失败了,即.它没有通过验证,它应该再次呈现初始化更新的操作,以便它可以显示适当的错误消息.
When you try to save one of those forms, and it fails, ie. it didn't pass validation, it should render the action that initialized the update again, so it can display appropiate error messages.
但问题是,我如何知道两者中的哪一个请求更新,并呈现正确的更新?基本上某种等同于 redirect_to :back 是我在这里寻找的东西.
But the problem is, how do I know which of both requested the update, and render the right one? Basically some sort of equivalent of redirect_to :back is what I'm looking for here.
推荐答案
这很丑但有效 :)
render Rails.application.routes.recognize_path(request.referer)[:action]
这篇关于呈现启动更新的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!