ruby-on-rails – Rails flash:通知不起作用
发布时间:2020-12-17 03:28:02 所属栏目:百科 来源:网络整理
导读:我有这个代码: def create login(params[:email],params[:password]) if current_user flash[:notice] = "Welcome back #{current_user.email}" return redirect_to_first_page else flash[:notice] = "Email or password is wrong. Try again !" redirect_
我有这个代码:
def create login(params[:email],params[:password]) if current_user flash[:notice] = "Welcome back #{current_user.email}" return redirect_to_first_page else flash[:notice] = "Email or password is wrong. Try again !" redirect_to root_url end end 登录成功后,将设置闪存并重定向到第一页. return redirect_to root_url 但没有任何东西仍然没有显示 <%= flash_notice %> 我正在使用rails 3.1 解决方法
Chris Drappier是正确的,闪存哈希仅适用于一个请求.您可以使用“调用”方法
flash.keep [:notice] =“此消息将持续存在” 就个人而言,我喜欢在需要时将闪光灯保留在参数中.血腥的细节在这里: http://guides.rubyonrails.org/action_controller_overview.html#the-flash (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |