Hi i have the model SDTicket which has a field modified_by_id and it has to take data from session[:id] Now this SDTicket model has many associated models like Activity one of them So when ever an activity happens then also the value in session[:id] is to be go to modified_by_id field SDTicket has_many activities Activity belongs to SDTicket So for that what I am trying is in Activity model wrote in after_save like below after_save :update_sd_ticket def update_sd_ticket #Here I dont know how to get that session[:id] and fill that to modified_by_id self.service_desk_ticket.save end I also tried like to get session from a module by including it in activity model But that too not working.Could you please help to solve this Thanks in advance Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sijo Kg wrote:> Hi > i have the model SDTicket which has a field modified_by_id and it has > to take data from session[:id] Now this SDTicket model has many > associated models like Activity one of them So when ever an activity > happens then also the value in session[:id] is to be go to > modified_by_id field > > SDTicket has_many activities > Activity belongs to SDTicket > > So for that what I am trying is in Activity model wrote in > after_save like below > after_save :update_sd_ticket > def update_sd_ticket > #Here I dont know how to get that session[:id] and fill that to > modified_by_id > self.service_desk_ticket.save > end > > I also tried like to get session from a module by including it in > activity model But that too not working.Could you please help to solve > thisThe session hash is only available in the controller and view. You''ll have to add a line to your controller method before your call to save activity.modified_by_id = session[:id] -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This blog post outlines a common way to get the current logged in user in your models... http://www.zorched.net/2007/05/29/making-session-data-available-to-models-in-ruby-on-rails/ On Dec 17, 6:54 pm, Mark Reginald James <m...-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> Sijo Kg wrote: > > Hi > > i have the model SDTicket which has a field modified_by_id and it has > > to take data from session[:id] Now this SDTicket model has many > > associated models like Activity one of them So when ever an activity > > happens then also the value in session[:id] is to be go to > > modified_by_id field > > > SDTicket has_many activities > > Activity belongs to SDTicket > > > So for that what I am trying is in Activity model wrote in > > after_save like below > > after_save :update_sd_ticket > > def update_sd_ticket > > #Here I dont know how to get that session[:id] and fill that to > > modified_by_id > > self.service_desk_ticket.save > > end > > > I also tried like to get session from a module by including it in > > activity model But that too not working.Could you please help to solve > > this > > The session hash is only available in the controller and view. > > You''ll have to add a line to your controller method before your > call to save > > activity.modified_by_id = session[:id] > > -- > Rails Wheels - Find Plugins, List & Sell Plugins -http://railswheels.com--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Hi Thanks for the link Sijo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---