class ActiveRecord::Base
Public Class Methods
method_missing(method, *args)
click to toggle source
LOOK INTO PASSING THE ARGS TO SUPER, MAYBE REMOVE thE *???
Calls superclass method
# File lib/find_by_shortcut.rb, line 16 def self.method_missing(method, *args) if method.to_s.starts_with?("fb") # Take all characters after "fb" remainder = method.to_s[2..-1] # Check if there is an attribute that starts with these chatacters attribute = self.new.attributes.keys.select{|e| e.starts_with?(remainder)}.first # If not, run the normal 'method missing' method if attribute == nil super else # but if so, call find by on that attribute new_method = "find_by_" + attribute send(new_method.to_s, args) end # if an unknown method doesn't start with fb, run the normal 'method missing' method else super end end