module Merb::ParamsFilter::RequestMixin
Attributes
trashed_params[RW]
Public Instance Methods
remove_params_from_object(obj, attrs = [])
click to toggle source
Removes specified parameters of an object
Parameters¶ ↑
- obj<Symbol>
-
Params key
- attrs<Array>
-
Attributes to restrict
Example¶ ↑
remove_params_from_object(:post, [:status, :author_id])
:api: plugin
# File lib/merb-param-protection.rb, line 143 def remove_params_from_object(obj, attrs = []) unless params[obj].nil? filtered = params attrs.each {|a| filtered[obj].delete(a)} @params = filtered end end
restrict_params(obj, attrs = [])
click to toggle source
Restricts parameters of an object
Parameters¶ ↑
- obj<Symbol>
-
Params key
- attrs<Array>
-
Attributes to restrict
Example¶ ↑
restrict_params(:post, [:title, :body])
:api: plugin
# File lib/merb-param-protection.rb, line 161 def restrict_params(obj, attrs = []) # Make sure the params for the object exists unless params[obj].nil? attrs = attrs.collect {|a| a.to_s} trashed_params_keys = params[obj].keys - attrs # Store a hash of the key/value pairs we are going # to remove in case we need them later. Lighthouse Bug # 105 @trashed_params = {} trashed_params_keys.each do |key| @trashed_params.merge!({key => params[obj][key]}) end remove_params_from_object(obj, trashed_params_keys) end end