instance method while_preventing_writes

Ruby on Rails 6.0.6

Since v6.0.6 Last seen in v7.0.10

Available in: v6.0.6 v6.1.7.10 v7.0.10

Signature

while_preventing_writes(enabled = true)

Prevent writing to the database regardless of role.

In some cases you may want to prevent writes to the database even if you are on a database that can write. while_preventing_writes will prevent writes to the database for the duration of the block.

This method does not provide the same protection as a readonly user and is meant to be a safeguard against accidental writes.

See READ_QUERY for the queries that are blocked by this method.

Parameters

enabled opt = true
Source
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 1044
      def while_preventing_writes(enabled = true)
        original, self.prevent_writes = self.prevent_writes, enabled
        yield
      ensure
        self.prevent_writes = original
      end

Defined in activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb line 1044 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::ConnectionHandler

Type at least 2 characters to search.

↑↓ navigate · open · esc close