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.
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.
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.
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.