【发布时间】:2011-03-25 04:12:37
【问题描述】:
所以当我退出并尝试投票时,我会被重定向到我的登录页面。查看这个问题,我询问了有关我的代码外观的更多详细信息:Redirect not working
现在我在我的会话目录中实现了一个 new.js.erb 文件(我遵循了我链接到的问题中接受的答案),它执行重定向。但是,我现在想在重定向到页面时添加一条自定义 Flash 消息,例如“您必须登录才能投票。”
我尝试添加这一行:
flash.now[:alert] = "You must be logged in to vote."
添加到我的会话控制器的新操作中,但这会在我进入登录页面时添加消息,即使我已经登录。我应该怎么做?
这是我正在使用的代码:
def access_denied
notices = {
:video_vote => {:new => "You must log in before voting"}
}
controller_name_sym = controller_name.to_sym
action_name_sym = action_name.to_sym
redirect_to login_path, :notice => (notices[controller_name_sym] && notices[controller_name_sym][action_name_sym] || "You must log in to perform this action.") and return false
end
【问题讨论】:
标签: ruby-on-rails ruby ajax ruby-on-rails-3 redirect