Created
April 1, 2010 15:39
-
-
Save lucasmncastro/351956 to your computer and use it in GitHub Desktop.
Revisions
-
lucasmncastro revised this gist
Apr 1, 2010 . 1 changed file with 7 additions and 5 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 @@ -2,19 +2,21 @@ module RequiredAttributes def self.included(base) base.class_eval do class << self @@required_attributes = [] def required?(attribute) @@required_attributes.include? attribute end def validates_presence_of_with_reader(*attr_names) validates_presence_of_without_reader(*attr_names) attr_names.extract_options! @@required_attributes += attr_names end alias_method_chain :validates_presence_of, :reader end end end end -
lucasmncastro created this gist
Apr 1, 2010 .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,20 @@ module RequiredAttributes def self.included(base) base.class_eval do class << self attr_accessor :required_attributes def validates_presence_of_with_reader(*attr_names) validates_presence_of_without_reader(*attr_names) attr_names.extract_options! self.required_attributes ||= [] self.required_attributes += attr_names end alias_method_chain :validates_presence_of, :reader end end end end ActiveRecord::Base.send :include, RequiredAttributes