开发者

Passing parameters in redirection, Rails

I am redirecting from one action "receive" to other "show" using

redirect_to @post

I need开发者_如何学Go to know if the visitor was redirected in the view for show

Can I store a variable @flag in receive and use it in "show" after the redirect? I couldn't.

Is there a way to pass a parameter without showing it in the URL?

Thanks in advance.


Use session/cookies for passing parameters without showing them in URLs. You could probably also hack the flash object and pass a custom key before redirecting:

flash[:from] = 'receive'
redirect_to @post


Sounds like you should store it in the session, maybe something like this in your receive action:

session[:redirected_from_receive] = true

Be sure to set this to false or nil in the show action. Alternatively, you can check the request.referer environment variable to see if it matches your receive page URL, but this is perhaps less reliable than using the session.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜