instance method find_by_attributes

Ruby on Rails 3.2.22.5

Since v3.0.20 Last seen in v3.2.22.5

Available in: v3.0.20 v3.1.12 v3.2.22.5

Signature

find_by_attributes(match, attributes, *args)

No documentation comment.

Parameters

match req
attributes req
args rest
Source
# File activerecord/lib/active_record/relation/finder_methods.rb, line 265
    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.nil?
        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

Defined in activerecord/lib/active_record/relation/finder_methods.rb line 265 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::FinderMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close