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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
373495071cec4b9f739e374007a15c30?d=identicon&s=25 Eric Nielsen (Guest)
on 2007-01-28 08: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
below)

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

Thanks
This topic is locked and can not be replied to.