I wrote a gem a while ago that adds sudo_* methods to ActiveRecord models to bypass mass-assignment protection, and I was curious if there would be any interest in adding similar functionality to Rails. I find it really useful when you want to quickly create a few records in the console, but can’t remember the syntax for “without_protection” or which role can update which attributes. Other potential uses could be for seed data and tests.
Here are a few examples of how you might use it:
# Given a User class class User < ActiveRecord::Base attr_accessible :name end
# Creating a new user > User.sudo_create(name: 'Pete', email: 'firstname.lastname@example.org', account: Account.first)
# Updating an existing user > new_account = Account.last > User.find(1).sudo_update_attributes(account: new_account)