开发者

Determining where parameters passed from view to controller originated

In my ApplicationController parent class I have an action method called dig which reads parameters via the params[] hash-like structure. I would like to have any view that builds a link to any controller via link_to helper function with the dig action to call the parent's action first. I'd like to then be able to determine either what that parameterized information represents (its type), or what created the link (the previous or originating view).

Any ideas o开发者_如何学Pythonn the best way to do this? Is there a way to pass an object via the link_to and then use its meta data? If so, would this break the rails paradigm?


If you're looking for what called what inside your code, Ruby's caller method is the basis for the stack dump that occurs when an exception occurs. You can tap into that and ask what the calling chain was at any point.

If you want to trace the incoming requests from the browser from an outside site, it becomes a lot more difficult because browsers don't like to reveal the last location any more. If the browser is being redirected around your own site you can use sessions or cookies to trace its movement.


I think that to have the originating link what you would need to do is something like this:

request.env['HTTP_REFERER']

This will get the URL where the action was originated, from there you can process the URL to get controller, action and id. Hope this helps!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜