Rails Flash 通知不在 url 上,而是在对象中 [英] Rails Flash notice not on url but in object

查看:27
本文介绍了Rails Flash 通知不在 url 上,而是在对象中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的用户控制器/模型中,我正在创建一个用户.当我重定向到用户

In my user controller/model I'm creating a user. When I redirect to user

format.html { redirect_to(@user, :notice => 'You have successfully registered!') }

我的页面上显示了一个很好的通知

I get a nice notice displayed on my page

当我尝试重定向到没有对象的不同控制器时

When I try to redirect to a different controller without an object

 format.html { redirect_to(:controller => 'profiles', :action => 'index', :notice => 'You have successfully registered!') }

我在 url 上收到通知,但没有显示在我的页面上.

I get the notice on the url and not displayed on my page.

profile?notice=You+have+successfully+registered%21

有什么办法可以将通知放入某个对象并显示在我的页面上?

is there any way to put the notice into some object and display it on my page?

推荐答案

format.html { 
 flash[:notice] = 'You have successfully registered!'
 redirect_to(:controller => 'profiles', :action => 'index') 
}

或者试试这个

format.html { redirect_to(:controller => 'profiles', :action => 'index'), :notice => 'You have successfully registered!' }

这篇关于Rails Flash 通知不在 url 上,而是在对象中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆