Redirecting to referer page after the sign up?

Im trying to redirect the user after the sign up by saving the referer
in case when user came to sign up through clicking on any specific page.
But its not working properly.

I’m using Devise, and i have 2 step registration, after sign up user
redirects to profile completion and it is mandatory and after that im
redirecting to referer. Please tell me what is the problem ?

In my application controller,

before_filter : save_referer

def save_referer
unless user_signed_in?
unless session[‘referer’]
session[‘referer’] = request.referer || ‘none’
end
end
end

In User Model,

def save_with(referer)
referer = referer unless referer == “null”
self.save
end

Initally i did self.referer but then i got undefined method `referer=’
for #User:0xc4a8bf0

Here im saving it,

if current_user.sign_in_count <= 1
if current_user.save_with(session[:referer])
redirect_to session[:referer]
else
redirect_to any_other
end
end

I’m not sure if this will work, but it is the best I can do at the
moment:

You’ll be better off asking the ruby on rails, I think.

@7stud,

Well i understand your point, but im not storing it in db. I just want
to redirect the user to referer page after sign up and is there any
better approach for this ? And im redirecting it after two step first
sign up and next profile completion.

Hussam A. wrote in post #1019017:

Im trying to redirect the user after the sign up by saving the referer
in case when user came to sign up through clicking on any specific page.
But its not working properly.

I’m using Devise, and i have 2 step registration, after sign up user
redirects to profile completion and it is mandatory and after that im
redirecting to referer. Please tell me what is the problem ?

In my application controller,

before_filter : save_referer

def save_referer
unless user_signed_in?
unless session[‘referer’]
session[‘referer’] = request.referer || ‘none’
end
end
end

In User Model,

def save_with(referer)
referer = referer unless referer == “null”
self.save
end

Of course, referer = referer doesn’t do anything. Suppose you did this:

x = 2
x = x

What do you think x is equal to now? Remember, computer programming
isn’t math class: assignment means take the value on the right and stuff
it in the variable on the left. Does the second line do anything?

Initally i did self.referer

Your initial instincts were good.

but then i got undefined method `referer=’
for #User:0xc4a8bf0

In ruby, if you write:

any_object.attribute = some_val

That is equivalent to:

any_object.attribute=(some_val)

In other words, you are calling a method named ‘attribute=’. So that
method has to be defined somewhere.

When you use rails to create your Model, for every column you specify
rails will create attributes for your model object, and also call
attr_accessor() for each attribute. If you don’t know what
attr_accessor() does, look it up.

If you don’t specify an attribute when you initially create your model,
you can add an attribute to your model with a migration, which will also
create the accessor methods. Or, if the attribute is a virtual
attribute, i.e. not saved in the db, then you have to manually call
attr_accessor in your model.

Based on your code, you look like you want referrer to be an attribute
of your model. Is that true? Do you want to save it in your db?
Did you add a referrer attribute to your model with a migration?

Or did you think you could just write:

self.any_old_name

and somehow that would save a value in your db?