Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Rails plugin for overriding attr_accessible protection.
branch: master

Merge pull request #5 from elandesign/master

Added gemspec and moved tasks
latest commit f9154144e6
@ryanb authored
Failed to load latest commit information.
lib Moved tasks into lib per deprecation warning
.gitignore Moved tasks into lib per deprecation warning
LICENSE initial import
README.rdoc adding links to beginning of readme
Rakefile Moved tasks into lib per deprecation warning
trusted_params.gemspec Moved tasks into lib per deprecation warning


Trusted Params

Rails plugin which adds a convenient way to override attr_accessible protection.

If you are unfamiliar with the dangers of mass assignment please check these links


You can install this as a plugin into your Rails app.

script/plugin install git://


This plugin does several things.

  • Adds “trust” method on hash to bypass attribute protection

  • Disables attr_protected because you should use attr_accessible.

  • Requires attr_accessible be specified in every model

  • Adds :all as option to attr_accessible to allow all attributes to be mass-assignable

  • Raises an exception when assigning a protected attribute (instead of just a log message)


When using this plugin, you must define attr_accessible in every model to allow mass assignment. You can use :all to mark all attributes as accessible.

class Comment < ActiveRecord::Base
  attr_accessible :all

However, only do this if you want all attributes accessible to the public. Many times you will want to limit what the general public can set.

class Comment < ActiveRecord::Base
  attr_accessible :author_name, :email, :content

Administrators should be able to bypass the protected attributes and set anything. This can be done with the “trust” method.

def create
  params[:comment].trust if admin?
  @comment =[:comment])
  # ...

You can mark certain attributes as trusted for different roles

params[:comment].trust(:spam, :important) if moderator?

Then only those attributes will be allowed to bypass mass assignment.

Something went wrong with that request. Please try again.