Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
filter_local_assigns_for_parti al
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Heather Moore  
View profile  
 More options Jan 6 2012, 6:52 pm
From: Heather Moore <heat...@needfeed.com>
Date: Fri, 6 Jan 2012 15:52:21 -0800 (PST)
Local: Fri, Jan 6 2012 6:52 pm
Subject: filter_local_assigns_for_partial
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Chaffee  
View profile  
 More options Jan 19 2012, 4:49 pm
From: Alex Chaffee <a...@stinky.com>
Date: Thu, 19 Jan 2012 13:49:11 -0800
Local: Thurs, Jan 19 2012 4:49 pm
Subject: Re: [erector] filter_local_assigns_for_partial
I'm not sure, but it probably relates to the following, let's be nice
and say "feature," in Rails. Every partial also has a local variable
with the same name as the partial (minus the underscore). You can pass
an object in to this local variable with a parameter named :object.

I can't see Erector's implementation of that in the code snippet you
sent but this is probably related. And I'm not saying the behavior you
described isn't also a bug.

 - A

--
Alex Chaffee - a...@stinky.com
http://alexchaffee.com
http://twitter.com/alexch


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Chaffee  
View profile  
 More options Jan 19 2012, 4:51 pm
From: Alex Chaffee <a...@stinky.com>
Date: Thu, 19 Jan 2012 13:51:09 -0800
Local: Thurs, Jan 19 2012 4:51 pm
Subject: Re: [erector] filter_local_assigns_for_partial
 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »