instance method wrap_parameters

Ruby on Rails 5.2.8.1

Since v5.2.8.1

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

wrap_parameters(name_or_model_or_options, options = {})

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.

Parameters

name_or_model_or_options req
options opt = {}
Source
# File actionpack/lib/action_controller/metal/params_wrapper.rb, line 207
      def wrap_parameters(name_or_model_or_options, options = {})
        model = nil

        case name_or_model_or_options
        when Hash
          options = name_or_model_or_options
        when false
          options = options.merge(format: [])
        when Symbol, String
          options = options.merge(name: name_or_model_or_options)
        else
          model = name_or_model_or_options
        end

        opts = Options.from_hash _wrapper_options.to_h.slice(:format).merge(options)
        opts.model = model
        opts.klass = self

        self._wrapper_options = opts
      end

Defined in actionpack/lib/action_controller/metal/params_wrapper.rb line 207 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionController::ParamsWrapper::Options::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close