Created
February 3, 2010 12:47
-
-
Save mauricio/293577 to your computer and use it in GitHub Desktop.
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 characters
| ActiveRecord::AttributeMethods.class_eval do #:nodoc: | |
| def method_missing(method_id, *args, &block) | |
| method_name = method_id.to_s | |
| if self.class.private_method_defined?(method_name) | |
| raise NoMethodError.new("Attempt to call private method", method_name, args) | |
| end | |
| # If we haven't generated any methods yet, generate them, then | |
| # see if we've created the method we're looking for. | |
| if !self.class.generated_methods? | |
| self.class.define_attribute_methods | |
| if self.class.generated_methods.include?(method_name) | |
| return self.send(method_id, *args, &block) | |
| end | |
| end | |
| if self.class.primary_key.to_s == method_name | |
| read_attribute('id') #this is the line changed | |
| elsif md = self.class.match_attribute_method?(method_name) | |
| attribute_name, method_type = md.pre_match, md.to_s | |
| if @attributes.include?(attribute_name) | |
| __send__("attribute#{method_type}", attribute_name, *args, &block) | |
| else | |
| super | |
| end | |
| elsif @attributes.include?(method_name) | |
| read_attribute(method_name) | |
| else | |
| super | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment