I would like to add a parameter to each URL in my Rails 2.3.10 application. I played with the default_url_options
but I want the parameter to be visible in the URL. Something like:
http://<server>/posts?token=XYZ
I'm building an affilate tracking system and I want people to share the link and be able to track who's link was used later when someone clicks it (to give points to the guy who shared the link). Any hints how I can add a visible parameter in each URL used in the application?
Thanks!
With params . Inside your controller action's you can call params to access form & URL query data. What is params , exactly? It's a method that returns an ActionController::Parameters object, in practice it behaves a lot like a hash.
GET parameters (also called URL parameters or query strings) are used when a client, such as a browser, requests a particular resource from a web server using the HTTP protocol. These parameters are usually name-value pairs, separated by an equals sign = . They can be used for a variety of things, as explained below.
You should use request. original_url to get the current URL.
Rewrite url_for
module ActionView::Helpers::UrlHelper
def url_for options
options.merge! {:token => generate_token}
super
end
end
or just add this to your application.rb
file
config.default_url_options += {:token => proc{generate_token}}
define default_url_options in ApplicationController (or the relevant controller)
def default_url_options
{subdomain: 'www'}
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With