method

find_by_attributes

find_by_attributes(match, attributes, *args)
protected

No documentation available.

# File activerecord/lib/active_record/relation/finder_methods.rb, line 261
    def find_by_attributes(match, attributes, *args)
      conditions = Hash[attributes.map {|a| [a, args[attributes.index(a)]]}]
      result = where(conditions).send(match.finder)

      if match.bang? && result.blank?
        raise RecordNotFound, "Couldn't find #{@klass.name} with #{conditions.to_a.collect {|p| p.join(' = ')}.join(', ')}"
      else
        yield(result) if block_given?
        result
      end
    end

1Note

for finding content

rakshit ยท Aug 17, 2013

it will use all the field related to particular table so you can find data by any table field like Table name => ABC(:id, :name, :address) if you want to find data related to id or name or address than only write

ABC.find_by_id(1)

ABC.find_by_name("abc")

ABC.find_by_address("abc")

find_by_field_name will find only first data match with it

if u want to find all data than enter

ABC.find_all_by_id(1)

ABC.find_all_by_name("abc")

ABC.find_all_by_name("abc")