开发者

Is there a clean way to preserve a parameter in a Rails controller?

We have a few self-contained pages in part of our mobile site which allow a user to sign up for a service. We have arrangements with other companies who send visitors to these pages, and they put a tracking code into the URL so we know who brought us the traffic - e.g. /mobile/landing?t=some_partner

We can't rely on the user's browser supporting cookies, so in order to preserve this information from the landing page to the sign-up event, we preserve the tracking code parameter in all the links and forms on the pages. At the moment, we have to add it to every link_to, form_tag, redirect_to and so on that we use. It's easy to add a link and forget to add the tracking code, so I'd like something more robust. Ideally I'd put at the top of the controller

preserve_parameter :t

and then every link_to, link_to, form_tag, redirect_to, etc... would automatically use the t parameter from the current request.开发者_运维知识库

Is there a plugin or gem anywhere that would let me do this, or do I need to write it myself?


I don't know of any gem/plugin, but i think that you can use url_for and create helpers to do that work for you in style :

http://apidock.com/rails/ActionView/Helpers/UrlHelper/url_for

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜