instance method setup

Ruby on Rails 6.0.6

Since v3.2.22.5 Last seen in v6.0.6 Private

Available in: v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6

Signature

setup(context, options, as, block)

Sets up instance variables needed for rendering a partial. This method finds the options and details and extracts them. The method also contains logic that handles the type of object passed in as the partial.

If options[:partial] is a string, then the @path instance variable is set to that string. Otherwise, the options[:partial] object must respond to to_partial_path in order to setup the path.

Parameters

context req
options req
as req
block req
Source
# File actionview/lib/action_view/renderer/partial_renderer.rb, line 374
      def setup(context, options, as, block)
        @options = options
        @block   = block

        @locals  = options[:locals] || {}
        @details = extract_details(options)

        partial = options[:partial]

        if String === partial
          @has_object = options.key?(:object)
          @object     = options[:object]
          @collection = collection_from_options
          @path       = partial
        else
          @has_object = true
          @object = partial
          @collection = collection_from_object || collection_from_options

          if @collection
            paths = @collection_data = @collection.map { |o| partial_path(o, context) }
            if paths.uniq.length == 1
              @path = paths.first
            else
              paths.map! { |path| retrieve_variable(path, as).unshift(path) }
              @path = nil
            end
          else
            @path = partial_path(@object, context)
          end
        end

        self
      end

Defined in actionview/lib/action_view/renderer/partial_renderer.rb line 374 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::PartialRenderer

Type at least 2 characters to search.

↑↓ navigate · open · esc close