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

Mr. Cheung, I was reading your 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: <p> 2: <%= form.label :account_id %><br /> 3: <%= form.text_field :account_id, :class => 'text_field', :size => 2 %> 4: </p> 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

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

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 %>

  <p>     <%= form.submit "Update" %>   </p> <% end %>

Then in my _form view it looks something like this;

  <p>     <%= form.label :account_id %><br />     <%= form.text_field :account_id, :class => 'text_field', :size => 2 %>   </p>

  <p>     <%= form.label :description %><br />     <%= form.text_field :description %>   </p>

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

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 %>

<p>    <%= form.submit "Update" %> </p> <% end %>

Then in my _form view it looks something like this;

<p>    <%= form.label :account_id %><br />    <%= form.text_field :account_id, :class => 'text_field', :size => 2 %> </p>

<p>    <%= form.label :description %><br />    <%= form.text_field :description %> </p>

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