This answer is responsible for additional questions asked in the comments to the question.
You cannot call find_or_create_by_name by default if you override this method. But you can implement your own, as shown below:
def self.find_or_create_by_name(*args) options = args.extract_options! options[:name] = args[0] if args[0].is_a?(String) case_sensitive = options.delete(:case_sensitive) conditions = case_sensitive ? ['name = ?', options[:name]] : ['UPPER(name) = ?', options[:name].upcase] first(:conditions => conditions) || create(options) end
Now you can call the overridden method as follows:
User.find_or_create_by_name("jack") User.find_or_create_by_name("jack", :case_sensitive => true) User.find_or_create_by_name("jack", :city=> "XXX", :zip => "1234") User.find_or_create_by_name("jack", :zip => "1234", :case_sensitive => true)
Harish shetty
source share