Getting a variable defined in new action in create action

Suppose there are two models, one is User model and other is Referral
model. The root is root :to => 'users#new. Now the user will coming
here via example.com/value, where value is the id for Referral model.
Now using this value I have to increment two fields: One is visits,
which shows how many visits did that particular url bring. Other is
signup, which will increment if there is a signup using that value.

I have passed this value via routes in users#new, which I use to
increment the visits column of Referral model. Now if the users
signup, the users#create would be executed, and I want to be able to
use the value in the create action as well, to increment the signup
column in Referral model.

As of now, I understand that the instance variable I created in new
action to store the value cannot be used in create action. Now how can
I achieve this.

On Oct 16, 1:47pm, Colin L. [email protected] wrote:

You could save it in the session.

Colin

Can you show me with a example, railsguide does not has very good
documentation on sessions. I do not understand, where to initialize
sessions and how to use.

On 17 October 2011 08:53, Nikhil G. [email protected] wrote:

sessions and how to use.
I think
Action Controller Overview — Ruby on Rails Guides
pretty much covers it. It is very simple as can be seen in the
examples there. Just set a value in the session in the controller
(something like session[:current_user_id] = user.id for example) and
access it again in a later action. Initially at least you can just
leave all the session config stuff at default and just go ahead and
use it.

Colin

On 16 October 2011 09:19, Nikhil G. [email protected] wrote:

use the value in the create action as well, to increment the signup
column in Referral model.

As of now, I understand that the instance variable I created in new
action to store the value cannot be used in create action. Now how can
I achieve this.

You could save it in the session.

Colin

There is not much to explain…

Just use session[:key] and it will work. Rails handles all the other
stuff
for you.

Only thing someone other has to explain would be expiering.


send by Samsung Galaxy Tab with Overcome Mod
Am 17.10.2011 09:53 schrieb “Nikhil G.” [email protected]: