public
Description: Restrict the params which we allow to get through to the action
Homepage:
Clone URL: git://github.com/jonleighton/restrict_params.git
name age message
file MIT-LICENSE Thu Sep 04 13:38:29 -0700 2008 Initial import [jonleighton]
file README.textile Fri Sep 05 14:29:54 -0700 2008 Finish the README [jonleighton]
file Rakefile Thu Sep 04 13:38:29 -0700 2008 Initial import [jonleighton]
file init.rb Thu Sep 04 13:38:29 -0700 2008 Initial import [jonleighton]
file install.rb Thu Sep 04 13:38:29 -0700 2008 Initial import [jonleighton]
directory lib/ Thu Sep 04 13:38:29 -0700 2008 Initial import [jonleighton]
directory spec/ Thu Sep 04 13:38:29 -0700 2008 Initial import [jonleighton]
directory tasks/ Thu Sep 04 13:38:29 -0700 2008 Initial import [jonleighton]
file uninstall.rb Thu Sep 04 13:38:29 -0700 2008 Initial import [jonleighton]
README.textile

Restrict Params

Restrict Params is a Rails plugin which enables you to specify a finite set of keys
which can appear in the parameters being passed to an action.

Why?

If you use a RESTful architecture, you use the create and update actions to modify
resources. Depending on the access priveliges of the application, you might want to,
for example, allow admins to modify all attributes of a Company model, but only allow
general users to modify the “notes” attribute.

Example

class CompaniesController < ApplicationController
  restrict_params :to => [:notes], :only => :update, :if => "!current_user.admin?"
end

The plugin will look at the class name of your controller and figure out that we need
to inspect params[:company]. If current_user.admin? is false, it will delete all items
from params[:company] except :notes.

See also

There is a similar merb plugin called
merb_param_protection.