Last active
October 13, 2015 18:47
Revisions
-
griffithac renamed this gist
Jun 16, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
griffithac revised this gist
Jun 16, 2013 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,5 +21,6 @@ end ## Add Database Columns ```shell rails g migration add_creator_id_and_updater_id_to_posts creator_id:integer updater_id:integer ```` -
griffithac renamed this gist
Jun 16, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
griffithac revised this gist
Dec 8, 2012 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,6 @@ def self.included(base) before_save :set_creator_and_updater belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' belongs_to :updater, :class_name => 'User', :foreign_key => 'updater_id' attr_accessible :current_user end end -
griffithac revised this gist
Dec 8, 2012 . 1 changed file with 25 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ ## Add Modules to Your App Ownership::Model Ownership::Controller ## Include Modules in your Model and Controller ~~~~ruby class Post < ActiveRecord::Base include Ownership::Model .... end class PostsController < ApplicationController include Ownership::Controller .... end ~~~~ ## Add Database Columns $ rails g migration add_creator_id_and_updater_id_to_posts creator_id:integer updater_id:integer -
griffithac revised this gist
Dec 8, 2012 . 1 changed file with 16 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,24 @@ module Ownership module Model def self.included(base) base.instance_eval do before_save :set_creator_and_updater belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' belongs_to :updater, :class_name => 'User', :foreign_key => 'updater_id' validates_presence_of :creator, :updater attr_accessible :current_user end end def current_user=(id) @current_user = User.find(id) end def current_user() @current_user end private @@ -26,20 +30,26 @@ def set_creator_and_updater self.updater_id = @current_user.id end end end module Controller def self.included(base) base.class_eval do before_filter :add_ownership_to_params def add_ownership_to_params model_key = self.class.to_s.gsub(/sController/, '').underscore.to_sym if params[model_key].present? && current_user params[model_key][:current_user] = current_user.id.to_s end end end end end end -
griffithac created this gist
Dec 8, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ module Ownership module Model def self.included(base) base.instance_eval do before_save :set_creator_and_updater belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' belongs_to :updater, :class_name => 'User', :foreign_key => 'updater_id' validates_presence_of :creator, :updater attr_accessible :current_user end end def current_user=(id) @current_user = User.find(id) end def current_user() @current_user end private def set_creator_and_updater if self.creator_id.nil? then self.creator_id = @current_user.id self.updater_id = @current_user.id else self.updater_id = @current_user.id end end end module Controller def self.included(base) base.class_eval do before_filter :add_ownership_to_params def add_ownership_to_params model_key = self.class.to_s.gsub(/sController/, '').underscore.to_sym if params[model_key].present? && current_user params[model_key][:current_user] = current_user.id.to_s end end end end end end