instance method
setup
Ruby on Rails 5.2.8.1
Since v3.2.22.5 Last seen in v6.0.6 PrivateSignature
setup(context, options, 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
-
contextreq -
optionsreq -
blockreq
Source
# File actionview/lib/action_view/renderer/partial_renderer.rb, line 361
def setup(context, options, block)
@view = context
@options = options
@block = block
@locals = options[:locals] || {}
@details = extract_details(options)
prepend_formats(options[:formats])
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) }
@path = paths.uniq.one? ? paths.first : nil
else
@path = partial_path
end
end
if as = options[:as]
raise_invalid_option_as(as) unless /\A[a-z_]\w*\z/.match?(as.to_s)
as = as.to_sym
end
if @path
@variable, @variable_counter, @variable_iteration = retrieve_variable(@path, as)
@template_keys = retrieve_template_keys
else
paths.map! { |path| retrieve_variable(path, as).unshift(path) }
end
self
end
Defined in actionview/lib/action_view/renderer/partial_renderer.rb line 361
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::PartialRenderer