开发者

Bubble notices through redirects

开发者 https://www.devze.com 2023-03-13 11:50 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消