title: How do I prevent model update from changing an attribute?
body: <p>I have <code>Account</code> model with attribute <code>role</code>. Roles wrote with <code>enum role: [:user, :admin]</code>. I want that if left one account with role <code>admin</code> he can't update his role to <code>user</code>. I think need to write something like this: <code>@account = Account.where(role: params[: role])...</code> and then I don't know.</p>
  
  <p><strong>account.rb</strong></p>
  
  <pre><code>class Account &lt; ApplicationRecord
    enum role: [:user, :admin]
  end
  </code></pre>
  
  <p><strong>accounts_controller.rb</strong></p>
  
  <pre><code>class AccountsController &lt; ApplicationController
    def index
      @accounts = Account.all
    end
    def update
      @account = Account.find(params[:id])
      redirect_to accounts_path if account.update(role: params[:role])
    end
  end
  </code></pre>
  
  <p><strong>schema.rb</strong></p>
  
  <pre><code>create_table "accounts", force: :cascade do |t|
    t.integer "role", default: 0
  end
  </code></pre>