instance method set

Ruby on Rails 7.1.6

Since v5.2.8.1

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

Signature

set(set_attributes)

Expose one or more attributes within a block. Old values are returned after the block concludes. Example demonstrating the common use of needing to set Current attributes outside the request-cycle:

class Chat::PublicationJob < ApplicationJob
  def perform(attributes, room_number, creator)
    Current.set(person: creator) do
      Chat::Publisher.publish(attributes: attributes, room_number: room_number)
    end
  end
end

Parameters

set_attributes req
Source
# File activesupport/lib/active_support/current_attributes.rb, line 211
    def set(set_attributes)
      old_attributes = compute_attributes(set_attributes.keys)
      assign_attributes(set_attributes)
      yield
    ensure
      assign_attributes(old_attributes)
    end

Defined in activesupport/lib/active_support/current_attributes.rb line 211 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::CurrentAttributes

Type at least 2 characters to search.

↑↓ navigate · open · esc close