# Trying to take :locals out of my partial call in Rails 2.1

**URL:** <https://www.ruby-forum.com/t/trying-to-take-locals-out-of-my-partial-call-in-rails-2-1/141417>\
**Category:** Rails\
**Created:** [June 25, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/trying-to-take-locals-out-of-my-partial-call-in-rails-2-1/141417 "2008-06-25T17:04:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 25, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/trying-to-take-locals-out-of-my-partial-call-in-rails-2-1/141417/1 "2008-06-25T17:04:49Z")

</div>

Mr. Cheung,  
I was reading your [http://www.spacevatican.org/](http://www.spacevatican.org/) and in your May 3rd  
blog you discuss a topic of which I show (below);  
When I try to take the :locals out of my partial call, the form blows  
up with this message;  
You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.label  
Extracted source (around line #2):  
1:

2: \<%= form.label :account\_id %\>  
  
3: \<%= form.text\_field :account\_id, :class =\> ‘text\_field’, :size  
=\> 2 %\>  
4:

  
I’ve read elsewhere of this new change in Rails 2.1.0 but cannot get  
my application to behave in this new way. I am certain I am using 2.1.

ARTICLE begins here  
:locals and string keys  
May 3rd, 2008  
If you ever do this  
render :some\_partial, :locals =\> {‘foo’ =\> ‘bar’}  
don’t. String keys in :locals have been deprecated for a while and are  
no longer supported in edge (and thus in the not too distant 2.1), so  
go ahead and change them now and you’ll save yourself some grief when  
you migrate to 2.1.  
When things break it’s always nice when they break in an obvious way,  
so in this case foo not being defined at all in the partial makes it  
immediately obvious that something has change from :locals. You check  
the api docs, maybe google around a bit and see that string keys  
aren’t accepted any more. If you do use a string key like this the foo  
will still be defined it will just be nil. You probably won’t suspect  
an api change and spend some time hunting up and down as to why the  
variable you’re using in :locals is nil (at least that’s what I did -  
hopefully you won’t have to do the same now!).  
ARTICLE ends here  
Thank you,  
Kathleen

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 25, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/trying-to-take-locals-out-of-my-partial-call-in-rails-2-1/141417/2 "2008-06-25T17:09:32Z")

</div>

On 25 Jun 2008, at 16:04, removed\_email\_address@domain.invalid wrote:

> 2: \<%= form.label :account\_id %\>  
>   
> 3: \<%= form.text\_field :account\_id, :class =\> ‘text\_field’, :size  
> =\> 2 %\>  
> 4:
> 
>   
> I’ve read elsewhere of this new change in Rails 2.1.0 but cannot get  
> my application to behave in this new way. I am certain I am using 2.1.

I probably wasn’t quite clear enough. I wasn’t saying don’t  
use :locals, I was saying don’t use string keys, so

:locals =\> {‘foo’ =\> ‘bar’}

becomes

:locals =\> {:foo =\> ‘bar’}

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 25, 2008, 5:45pm UTC](https://www.ruby-forum.com/t/trying-to-take-locals-out-of-my-partial-call-in-rails-2-1/141417/3 "2008-06-25T17:45:56Z")

</div>

Mr. Cheung,  
I stumbled upon the fact that if I take the quotes off of ‘form’ that  
it works.  
\<% form\_for(@agency) do |form| %\>  
\<%= form.error\_messages %\>

\<%= render :partial =\> form %\>

\<%= form.submit "Update" %\>

\<% end %\>

Then in my \_form view it looks something like this;

\<%= form.label :account\_id %\>  
 \<%= form.text\_field :account\_id, :class =\> 'text\_field', :size =\> 2 %\>

\<%= form.label :description %\>  
 \<%= form.text\_field :description %\>

Are you saying that I must put the locals back in even though it  
works?  
Thank you,  
Kathleen

On Jun 25, 9:08 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 25, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/trying-to-take-locals-out-of-my-partial-call-in-rails-2-1/141417/4 "2008-06-25T17:57:38Z")

</div>

On 25 Jun 2008, at 16:45, removed\_email\_address@domain.invalid wrote:

> \<%= form.label :description %\>  
> \<%= form.text\_field :description %\>
> 
> Are you saying that I must put the locals back in even though it  
> works?

No you don’t need to (that’s another rails 2.1 change, you can pass a  
form builder to :partial)

Fred
