Hello!
Today I ran into an interesting problem losing a variable when
rendering a partial.
As it turns out, there is a method that specifically strips local
assigns with the same name as the partial to be rendered. It goes
something like this:
if pink_lady = Apple.find_by_type("pink_lady")
render partial: "apples/pink_lady", locals: { pink_lady:
pink_lady }
end
Later, we get to the method, filter_local_assigns_for_partial, where
pink_lady is rejected from the collection.
def filter_local_assigns_for_partial(widget_class, local_assigns)
widget_class_variable_name = widget_class.name.underscore
widget_class_variable_name = $1 if widget_class_variable_name =~
%r{.*/(.*?)$}
local_assigns.reject do |name, value|
name == :object || name == widget_class_variable_name.to_sym
end
end
Can someone help me understand why this is done?
Thanks,
Heather