Forum: Ruby on Rails Possible bug in form_for...

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Eric N. (Guest)
on 2007-01-28 09:22
(Received via mailing list)
I'm not sure if I found a bug, or just an undocumented corner of
form_for and wanted to see if anyone here can provide any insight
before I open a Trac ticket.

When using form_form and passing multiple parameters to the :url hash
the block parameter wasn't getting initialized ("f" in the example

form_for :person, :url=>{:short_name=>@competition, :action=>:start}
do |f| -%>
<%= f.text_field :foo -%>
<% end -%>

Will result in an error message like "undefined local variable or
method "f" on the f.text_field line.   This error only occured in test
environments, never in production.

The above error happened under autotest and rake:test.  Running an
individual test case however would normally yield a "You have a nil
object .... nil.text_field" style error message insteaad.

If I change it to
<% form_for :person,
@person, :url=>{:short_name=>@competition, :action=>:start} do |f| -%>
<%= f.text_field :foo -%>
<% end -%>

it now works, but I was under the impression that the explicit model
object variable wasn't required.  Is this a bug in form_for? or is
there some undocumented requirement for the explicit model obejct in
certain cases?

This topic is locked and can not be replied to.