How to save http referer in rails

Posted by TenJack on Stack Overflow See other posts from Stack Overflow or by TenJack
Published on 2010-02-26T13:27:03Z Indexed on 2010/03/09 2:21 UTC
Read the original article Hit count: 407

I'm trying to save the site that a user came from when they sign up. Right now I have a before_filter in my ApplicationController:

before_filter :save_referer

  def save_referer
    unless is_logged_in?
      session['referer'] = request.env["HTTP_REFERER"] unless session['referer']
    end
  end

Then when a user is created, it checks this session variable and sets it to nil. Sometimes this does not work and I'm worried there might be some unintended things happening with using session like this. Does anyone have a better way? Or some input perhaps?

EDIT: This is the logic I am using to save the referer:

def create
@user = User.new(params[:user])
if @user.save_with(session[:referer]) .... end

User def save_with(referer) self.referer = referer unless referer == "null" self.save
end

Is there any reason why this should not work?

© Stack Overflow or respective owner

Related posts about session

Related posts about ruby-on-rails