Definite newbie here - I’m working through this like-hate relationship
Ruby and Rails right now… sometimes things work really well (like
seem to rock) but other times, I dunno!
Anyway, I’d like put in create and update user timestamps on all my
domain tables and allow them to be updated automatically by
Coming from Hibernate, I just place an interceptor that dynamically
discovers the column names and sets it up. In Ruby, I’m totally lost.
However, I hold out hope - I just don’t know the terminology for what
looking for since what I’m doing has to be relatively common.
So, I’ve created a mixin called UserTimestamp.rb:
self.created_on = Time.new
self.created_by = @user.user_id
self.updated_on = Time.new
self.updated_by = @user.user_id
And, then I include it and setup the before_create and after_create
class Video < ActiveRecord::Base
Of course, this doesn’t work, but that seemed logical. Neither @user or
is present, nor do I have any way to get the user_id. User is identified
my ApplicationController by a filter which is available in all my
controllers. However, I have absolutely no way of locating the User
from an ActiveRecord class… or do I? Do I need to pass it in on create
something weird like that? (Or, yuck, manually invoke it??)
Is there a better way to do this? This does work, but I wonder if
more appropriate manner.
Thanks for any feedback!