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