Bubble notices through redirects
My scenario:
In my controller, after confirm开发者_StackOverflow中文版ing the user, I redirect to root (a landing page: statics#landing
) and I attach a notice:
redirect_to root_url, notice: 'Confirmation successful.'
but there, I always check if the user is already signed in, and if so I'm redirecting him to the actual index:
def landing
redirect_to actual_index_url if (user.signed_in?)
end
How can I propagate the confirmation notice to the last page?
I think you're looking for flash.keep
.
http://railsapi.com/doc/rails-v3.0.8rc1/classes/ActionDispatch/Flash/FlashHash.html#M006014
Try:
def landing
redirect_to actual_index_url, :notice => flash[:notice] if (user.signed_in?)
end
flash.keep(:notice)
- if you want to keep only notices just flash.keep
will keep both :notices
and :errors
.
精彩评论