Forum: Ruby on Rails session In the model

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
661ae6e97d0e16c2af2aaf7d197e8387?d=identicon&s=25 Sijo k g (sijo)
on 2008-12-13 07:04
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
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2008-12-18 01:55
(Received via mailing list)
Sijo Kg wrote:
>      So for that what I am trying is in Activity model wrote in
> 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
F0992e02cf3083a34dca02b5822ee46f?d=identicon&s=25 Wally Valters (Guest)
on 2008-12-18 14:53
(Received via mailing list)
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-d...
661ae6e97d0e16c2af2aaf7d197e8387?d=identicon&s=25 Sijo k g (sijo)
on 2008-12-19 10:11
Hi
   Thanks for the link
Sijo
This topic is locked and can not be replied to.