Nikhil Goyal
2011-Oct-16 08:19 UTC
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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Oct-16 08:47 UTC
Re: Getting a variable defined in new action in create action
On 16 October 2011 09:19, Nikhil Goyal <goyal.nikhil89-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.You could save it in the session. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Nikhil Goyal
2011-Oct-17 07:53 UTC
Re: Getting a variable defined in new action in create action
On Oct 16, 1:47 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> You could save it in the session. > > ColinCan 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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Oct-17 08:14 UTC
Re: Re: Getting a variable defined in new action in create action
On 17 October 2011 08:53, Nikhil Goyal <goyal.nikhil89-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Oct 16, 1:47 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> 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.I think http://guides.rubyonrails.org/action_controller_overview.html#session 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Norbert Melzer
2011-Oct-17 13:30 UTC
Re: Re: Getting a variable defined in new action in create action
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 Goyal" <goyal.nikhil89-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > > On Oct 16, 1:47 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> 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. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.