Removes specified parameters of an object
obj<Symbol> |
Params key |
attrs<Array> |
Attributes to restrict |
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
Restricts parameters of an object
obj<Symbol> |
Params key |
attrs<Array> |
Attributes to restrict |
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
Generated with the Darkfish Rdoc Generator 2.