我有一个 设置 Controller 用行动帐号和 个人资料 ,还有一个 更新 看起来像:
def update
@player = current_user
if @player.update_attributes(params[:player])
flash[:success] = "Profile updated."
redirect_to :back
else
@title = "Edit"
render
end
end
现在 profile 和 account 操作都有一个对应的 View ,有一个表单来编辑 Player 模型的一些记录。
当您尝试保存其中一种表格时,它失败了,即。它没有通过验证,它 应该呈现初始化更新的操作 再次,因此它可以显示适当的错误消息。
但问题是,我怎么知道两者中的哪一个请求更新,并呈现正确的更新?基本上某种等同于 redirect_to :back 是我在这里寻找的。
最佳答案
这很丑但有效:)
render Rails.application.routes.recognize_path(request.referer)[:action]
关于ruby-on-rails - 呈现启动更新的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5207846/