instance method
setup
Ruby on Rails 4.1.16
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 323
def setup(context, options, block)
@view = context
partial = options[:partial]
@options = options
@locals = options[:locals] || {}
@block = block
@details = extract_details(options)
prepend_formats(options[:formats])
if String === partial
@object = options[:object] if options.has_key?(:object)
@path = partial
@collection = collection
else
@object = partial
if @collection = collection_from_object || collection
paths = @collection_data = @collection.map { |o| partial_path(o) }
@path = paths.uniq.size == 1 ? paths.first : nil
else
@path = partial_path
end
end
if as = options[:as]
raise_invalid_option_as(as) unless as.to_s =~ /\A[a-z_]\w*\z/
as = as.to_sym
end
if @path
@variable, @variable_counter = 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 323
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::PartialRenderer