I wrote a gem <https://github.com/beerlington/sudo_attributes> 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 :nameend

# Creating a new user> User.sudo_create(name: 'Pete', email: 
'[email protected]', account: Account.first)

# Updating an existing user
> new_account = Account.last
> User.find(1).sudo_update_attributes(account: new_account)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-core/-/D1l2gNvoaoQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to