instance method find_signed!

Ruby on Rails 8.1.2

Since v6.1.7.10

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

find_signed!(signed_id, purpose: nil, on_rotation: nil)

Works like find_signed, but will raise an ActiveSupport::MessageVerifier::InvalidSignature exception if the signed_id has either expired, has a purpose mismatch, is for another record, or has been tampered with. It will also raise an ActiveRecord::RecordNotFound exception if the valid signed id can’t find a record.

Examples

User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature

signed_id = User.first.signed_id
User.first.destroy
User.find_signed! signed_id # => ActiveRecord::RecordNotFound

Parameters

signed_id req
purpose key = nil
on_rotation key = nil
Source
# File activerecord/lib/active_record/signed_id.rb, line 89
      def find_signed!(signed_id, purpose: nil, on_rotation: nil)
        options = { on_rotation: on_rotation }.compact
        if id = signed_id_verifier.verify(signed_id, purpose: combine_signed_id_purposes(purpose), **options)
          find(id)
        end
      end

Defined in activerecord/lib/active_record/signed_id.rb line 89 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::SignedId::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close