Forum: Ruby on Rails form_for with divs and fieldsets => stupid

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.
Amos K. (Guest)
on 2007-06-06 04:53
(Received via mailing list)
If I do this:

+============================================+
<div class="form" id="form" style="display : none;">
  <fieldset>
    <% form_for :item, :url => { :controller => 'inventory', :action
=> 'create' } do |f| %>
      <%= render :partial => 'item_form', :locals => { :f => f } %>
      <%= submit_tag "Add" %>
    <% end %>
  </fieldset>
</div>
+============================================+

I get:

+============================================+
<div style="display: none;" id="form" class="form">
<fieldset>
</fieldset>
</div>

<p>
<label for="item_description">
Item
</label>
  <input size="20" name="item[description]" id="item_description"
type="text">
<label for="item_on_hand">
Qty
</label>
  <input size="5" name="item[on_hand]" id="item_on_hand" type="text">
<label for="item_year">
Year
</label>
  <input value="2007" size="4" name="item[year]" id="item_year"
disabled="disabled" type="text">
</p>
+============================================+



I don't get why the form shows up outside the div and fieldset.  If I
move them inside the form_for block everything works as expected.
This behavior seems really strange.  Is there are reason why it is
this way, or is this a bug?

--
Amos K.
A. King Software Development and Consulting, L.C.
http://dirtyInformation.com
--
Looking for something to do? Visit http://ImThere.com
Gabe da Silveira (Guest)
on 2007-06-06 07:15
(Received via mailing list)
Something's going wrong because the form tag is not being generated at
all.  I'm surprised there's not an error though.  The only thing pops
out at me is the fact that you aren't passing an object to it.
Typically form_for is called like:

form_for :item, @item, :url => .....

Where :item is the name, and @item provides the values for form
persistence.

On 6/5/07, Amos K. <removed_email_address@domain.invalid> wrote:
>     <% end %>
> </div>
> <label for="item_year">
> move them inside the form_for block everything works as expected.
> >
>


--
Gabe da Silveira
http://darwinweb.net
James M. (Guest)
on 2007-06-06 07:39
(Received via mailing list)
I don't claim to know why this is happening, but what happens when
you move the form_for into the partial?

Also, shouldn't you have fieldset inside your form_for?


<div class="form" id="form" style="display : none;">
   <fieldset>
       <%= render :partial => 'item_form', :locals => { :f => f } %>
   </fieldset>
</div>



----
_item_form.rhtml


     <% form_for :item, :url => { :controller => 'inventory', :action
=> 'create' } do |f| %>

       <%= submit_tag "Add" %>
     <% end %>

--
James M.
(Guest)
on 2007-06-06 18:45
(Received via mailing list)
I moved the div and the fieldset inside the form_for and it works.  I
just don't know why when I put the tags outside it doesn't get
generated in the right place.  I just want to know if there is a
reason for this behavior.  I also don't know why a form tag wasn't
created.  I never tried to submit anything when the form was
displaying outside the fieldset.

Gabe: You only need to pass an object in if the form is going to be
pre-populated.  At least that is my understanding.

There is some refactoring being done.  The divs and fieldsets and
form_fors are being moved to the partial.

On Jun 5, 10:39 pm, James M. <removed_email_address@domain.invalid>
dasil003 (Guest)
on 2007-06-06 23:23
(Received via mailing list)
Wait, if you move the div and fieldset inside the form_for the form
tags are being generated correctly?  Or just the order comes out
correct?  The latter makes perfect sense, but the former would be
exceedingly strange.

On Jun 6, 8:44 am, "removed_email_address@domain.invalid" 
<removed_email_address@domain.invalid>
Amos K. (Guest)
on 2007-06-06 23:32
(Received via mailing list)
If I put the div and fieldset inside the form_for everything is
correct.  The form fields are inside the fieldset which in turn is
inside the div, and everything forks great.  If I place it as about
everything shows up out of order.  I'm using Rails 1.2.3 and Ruby
1.8.6.

On 6/6/07, dasil003 <removed_email_address@domain.invalid> wrote:
> > generated in the right place.  I just want to know if there is a
> > On Jun 5, 10:39 pm, James M. <removed_email_address@domain.invalid>
> > >    </fieldset>
> >
> > > >     <%form_for:item, :url => { :controller => 'inventory', :action
> > > > +============================================+
> > > > type="text">
> > > > +============================================+
> > > > --
> > > > Looking for something to do? Visithttp://ImThere.com
>
>
> >
>


--
Amos K.
A. King Software Development and Consulting, L.C.
http://dirtyInformation.com
--
Looking for something to do? Visit http://ImThere.com
This topic is locked and can not be replied to.