alexlevin / rack-affiliates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This gem works with localhost?

hyperrjas opened this issue · comments

1º This is my config:

config.middleware.use Rack::Affiliates, {:param => 'aff_id', :ttl => 6.months, :domain => '.localhost'}

2º I send a email with a link and param aff_id something like:
<%= link_to "accept invite", new_user_registration_url(:aff_id => @user.id) %>

3º In root action in a controller:

  def index
    if request.env['affiliate.tag'] && affiliate = User.find_by_affiliate_tag(request.env['affiliate.tag'])
      logger.info "Halo, referral! You've been referred here by #{affiliate.name} from #{request.env['affiliate.from']} @ #{Time.at(env['affiliate.time'])}"
    else
      logger.info "We're glad you found us on your own!"
    end
   respond_to do |format|
     format.html
   end
 end

I'm getting the message on console:

We're glad you found us on your own!

What am I doing wrong?

Thanks!

Same problem, did you resolve it before?

Thanks,

This is a side effect of issue #8. By default you can only read the cookie in a controller on the same path as the controller that originally set the cookie. e.g. a controller responding at http://localhost/users/new cannot read the cookie set by somebody visiting http://localhost/?ref=1234

To accept affiliate links on any route/controller in your app you can now hardcode the path across your app by adding the :path option

config.middleware.use Rack::Affiliates, {:param => 'aff_id', :ttl => 6.months, :domain => '.localhost', :path => "/"}

Make sure you update to version 0.3.0 of the gem to get this feature.