Module: ActionController::ParamsWrapper::ClassMethods
- Defined in:
- lib/action_controller/metal/params_wrapper.rb
Instance Method Summary collapse
- #_set_wrapper_options(options) ⇒ Object
-
#inherited(klass) ⇒ Object
Sets the default wrapper key or model which will be used to determine wrapper key and attribute names.
-
#wrap_parameters(name_or_model_or_options, options = {}) ⇒ Object
Sets the name of the wrapper key, or the model which
ParamsWrapper
would use to determine the attribute names from.
Instance Method Details
#_set_wrapper_options(options) ⇒ Object
189 190 191 |
# File 'lib/action_controller/metal/params_wrapper.rb', line 189 def () self. = Options.from_hash() end |
#inherited(klass) ⇒ Object
Sets the default wrapper key or model which will be used to determine wrapper key and attribute names. Called automatically when the module is inherited.
244 245 246 247 248 249 250 251 |
# File 'lib/action_controller/metal/params_wrapper.rb', line 244 def inherited(klass) if klass..format.any? params = klass..dup params.klass = klass klass. = params end super end |
#wrap_parameters(name_or_model_or_options, options = {}) ⇒ Object
Sets the name of the wrapper key, or the model which ParamsWrapper
would use to determine the attribute names from.
Examples
wrap_parameters format: :xml
# enables the parameter wrapper for XML format
wrap_parameters :person
# wraps parameters into +params[:person]+ hash
wrap_parameters Person
# wraps parameters by determining the wrapper key from Person class
# (+person+, in this case) and the list of attribute names
wrap_parameters include: [:username, :title]
# wraps only +:username+ and +:title+ attributes from parameters.
wrap_parameters false
# disables parameters wrapping for this controller altogether.
Options
-
:format
- The list of formats in which the parameters wrapper will be enabled. -
:include
- The list of attribute names which parameters wrapper will wrap into a nested hash. -
:exclude
- The list of attribute names which parameters wrapper will exclude from a nested hash.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/action_controller/metal/params_wrapper.rb', line 220 def wrap_parameters(, = {}) model = nil case when Hash = when false = .merge(format: []) when Symbol, String = .merge(name: ) else model = end opts = Options.from_hash .to_h.slice(:format).merge() opts.model = model opts.klass = self self. = opts end |