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
Message from discussion Proposal: partials should not create a local variable with the name of the partial when no :local or :object option was passed

Received: by 10.224.70.131 with SMTP id d3mr5776700qaj.0.1348438042503;
        Sun, 23 Sep 2012 15:07:22 -0700 (PDT)
X-BeenThere: rubyonrails-core@googlegroups.com
Received: by 10.224.217.65 with SMTP id hl1ls10269248qab.8.gmail; Sun, 23 Sep
 2012 15:07:12 -0700 (PDT)
Received: by 10.224.207.197 with SMTP id fz5mr8853062qab.3.1348438032560;
        Sun, 23 Sep 2012 15:07:12 -0700 (PDT)
Received: by 10.224.207.197 with SMTP id fz5mr8853061qab.3.1348438032545;
        Sun, 23 Sep 2012 15:07:12 -0700 (PDT)
Return-Path: <sikand...@gmail.com>
Received: from mail-qc0-f182.google.com (mail-qc0-f182.google.com [209.85.216.182])
        by gmr-mx.google.com with ESMTPS id x33si3194318qci.3.2012.09.23.15.07.12
        (version=TLSv1/SSLv3 cipher=OTHER);
        Sun, 23 Sep 2012 15:07:12 -0700 (PDT)
Received-SPF: pass (google.com: domain of sikand...@gmail.com designates 209.85.216.182 as permitted sender) client-ip=209.85.216.182;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of sikand...@gmail.com designates 209.85.216.182 as permitted sender) smtp.mail=sikand...@gmail.com; dkim=pass header...@gmail.com
Received: by qcsg15 with SMTP id g15so995476qcs.13
        for <rubyonrails-core@googlegroups.com>; Sun, 23 Sep 2012 15:07:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:x-mailer
         :mime-version:content-type;
        bh=czwh/5QR/G26TX7D8htil+qgltdTCFKhCBtLaCrcqhk=;
        b=VRqjFNcf6lsV8oCDAzkOgz8DjuxXDhfbnErngB7P44Xo9Ygctl9KcA1aoGnc0aeGfa
         JW+DfY/qMvh/P3Q95A53fcqfYjHw6bt1pH17vVae6/f07QlhTRqX1glZBfII36eZ5z9W
         b4YpfAljdXrGgrhJTgMEKH4O+I5dxd0+ZdID3AjvsDUgQl7H2mB7WopKRIxwtl6JMFrF
         Bh+nDIA2v4rQ6YlwLKQu7OVRenwTC45tbs/DhBxzoHQUavRZFFHqGnOxzP4zpwEdURqF
         Vib+FjB5DVlkG96H9d85Y0BtOF7qyUsG7+pTFu+3137DxPhTdE0pHOPrFP2xqWxp/GR8
         6lWQ==
Received: by 10.224.183.146 with SMTP id cg18mr28257078qab.7.1348438032415;
        Sun, 23 Sep 2012 15:07:12 -0700 (PDT)
Return-Path: <sikand...@gmail.com>
Received: from [10.0.1.15] (c-76-24-24-86.hsd1.ma.comcast.net. [76.24.24.86])
        by mx.google.com with ESMTPS id e5sm22963621qao.11.2012.09.23.15.07.11
        (version=TLSv1/SSLv3 cipher=OTHER);
        Sun, 23 Sep 2012 15:07:11 -0700 (PDT)
Date: Sun, 23 Sep 2012 18:07:10 -0400
From: Prem Sichanugrist <sikand...@gmail.com>
To: rubyonrails-core@googlegroups.com
Message-ID: <9E43ECFEE6CB47C4966FDD618BE5E...@gmail.com>
In-Reply-To: <20120923203910.GC25...@higgins.local>
References: <fb2afa75-c379-446a-b4d4-5b6ed4f8e452@googlegroups.com>
 <20120923203910.GC25...@higgins.local>
Subject: Re: [Rails-core] Proposal: partials should not create a local
 variable with the name of the partial when no :local or :object option
 was passed
X-Mailer: sparrow 1.6.3 (build 1172)
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="505f880e_4db127f8_197"

--505f880e_4db127f8_197
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Right, I think I understand the problem incorrectly the first time.

If we do `render 'flash'`, then there should be no local variable name `flash` that is nil. Does Rails currently create a nil variable name `flash`?

- Prem 


On Sunday, September 23, 2012 at 4:39 PM, Aaron Patterson wrote:

> On Tue, Sep 18, 2012 at 12:01:59PM -0700, John Firebaugh wrote:
> > 
> > 
> > From this stack overflow question<http://stackoverflow.com/questions/3111844/flash-messages-in-partials-rails-3/12482879>
> > .
> > 
> > Suppose I have a partial _flash.html.erb for rendering the flash in a 
> > consistent way. The natural thing to do would be to assume I can call 
> > ActionView::Base#flash from within this partial to retrieve the flash, and 
> > render the partial withrender partial: "flash". But in fact, this doesn't 
> > work. Even though I haven't passed object: flash orlocals: {flash: flash} in 
> > the call to render partial, PartialRenderer oh-so-helpfully defines a flashlocal 
> > variable, whose value is nil, shadowing ActionView::Base#flash. My 
> > alternatives are to rename the partial or pass a value for the flash local 
> > explicitly using one of those more verbose call to render.
> > 
> > I suggest that if no object option or local with the same name as the 
> > partial was passed to the render call, thatPartialRenderer *not* define a 
> > local variable of the same name as the partial. This would change the 
> > behavior for anyone who is relying on the current behavior to get a nil value 
> > for the local when they don't pass an explicit value, but that seems like 
> > an unlikely case and easily fixed by passing nil explicitly, and it would 
> > be much more useful to do things like call ActionView::Base#flash from 
> > within a _flash.html.erb partial.
> > 
> > I'm happy to create a pull request if others agree.
> 
> Do you know where the code is that does this? I'd like to understand
> why we do it before agreeing / disagreeing.
> 
> -- 
> Aaron Patterson
> http://tenderlovemaking.com/
> 
> 



--505f880e_4db127f8_197
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline


                <div style=3D=22font-family: Helvetica; font-size: 13px; =
=22>Right, I think I understand the problem incorrectly the first time.<d=
iv><br></div><div>If we do =60render 'flash'=60, then there should be no =
local variable name =60flash=60 that is nil. Does Rails currently create =
a nil variable name =60flash=60=3F</div><div><br></div><div>- Prem</div><=
/div>
                <div></div>
                =20
                <p style=3D=22color: =23A0A0A8;=22>On Sunday, September 2=
3, 2012 at 4:39 PM, Aaron Patterson wrote:</p>
                <blockquote type=3D=22cite=22 style=3D=22border-left-styl=
e:solid;border-width:1px;margin-left:0px;padding-left:10px;=22>
                    <span><div><div><div>On Tue, Sep 18, 2012 at 12:01:59=
PM -0700, John =46irebaugh wrote:</div><blockquote type=3D=22cite=22><div=
><div><br></div><div><br></div><div>=46rom this stack overflow question&l=
t;<a href=3D=22http://stackoverflow.com/questions/3111844/flash-messages-=
in-partials-rails-3/12482879=22>http://stackoverflow.com/questions/311184=
4/flash-messages-in-partials-rails-3/12482879</a>&gt;</div><div>.</div><d=
iv><br></div><div>Suppose I have a partial =5Fflash.html.erb for renderin=
g the flash in a </div><div>consistent way. The natural thing to do would=
 be to assume I can call </div><div>ActionView::Base=23flash from within =
this partial to retrieve the flash, and </div><div>render the partial wit=
hrender partial: =22flash=22. But in fact, this doesn't </div><div>work. =
Even though I haven't passed object: flash orlocals: =7Bflash: flash=7D i=
n </div><div>the call to render partial, PartialRenderer oh-so-helpfully =
defines a flashlocal </div><div>variable, whose value is nil, shadowing A=
ctionView::Base=23flash. My </div><div>alternatives are to rename the par=
tial or pass a value for the flash local </div><div>explicitly using one =
of those more verbose call to render.</div><div><br></div><div>I suggest =
that if no object option or local with the same name as the </div><div>pa=
rtial was passed to the render call, thatPartialRenderer *not* define a <=
/div><div>local variable of the same name as the partial. This would chan=
ge the </div><div>behavior for anyone who is relying on the current behav=
ior to get a nil value </div><div>for the local when they don't pass an e=
xplicit value, but that seems like </div><div>an unlikely case and easily=
 fixed by passing nil explicitly, and it would </div><div>be much more us=
eful to do things like call ActionView::Base=23flash from </div><div>with=
in a =5Fflash.html.erb partial.</div><div><br></div><div>I'm happy to cre=
ate a pull request if others agree.</div></div></blockquote><div><br></di=
v><div>Do you know where the code is that does this=3F  I'd like to under=
stand</div><div>why we do it before agreeing / disagreeing.</div><div><br=
></div><div>-- </div><div>Aaron Patterson</div><div><a href=3D=22http://t=
enderlovemaking.com=22>http://tenderlovemaking.com</a>/</div></div></div>=
</span>
                =20
                =20
                =20
                =20
                </blockquote>
                =20
                <div>
                    <br>
                </div>
            
--505f880e_4db127f8_197--