rubyonrailsin

A Ruby and Rails talk

Sunday, March 28, 2010


[Rails] keeping track of who did what

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

hello everybody.
i need to log "who did what" on some models. i was reading recipe 59
of rails recipes and i created something like that:

class LogSweeper < ActionController::Caching::Sweeper
observe :model1, :model2, :model3, :model4, :model5, ...

after_save(model)
save_log(model, "save")
end

after_destroy(model)
save_log(model, "destroy)
end

private
save_log(model, event, user_id = controller.session[:account_id])
#create the log entry, i want to save the id of the model, the id
of the logged user and something to describe the action.
#controller isn't defined here so i can't access the user_id.
end
end

in environment.rb i added:
config.active_record.observers = :log_sweeper


the sweeper is called when something happen to the observed models,
but i can't access the controller (and so, the user_id) from there.
any help?

--
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@googlegroups.com.
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.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive