Should all form elements for a form be in a single div?


#1

My layout file is like this…

#printing the controller name
<%= yield%> #THIS IS WHERE THE NEW.HTML.ERB IS RENDERED
<%= yield :sidebox_1%>#SOME FORM ELEMENT ARE RENDERED IN HERE
<%= yield :sidebox_2%>#SOME FORM ELEMENT ARE RENDERED IN HERE

If you notice, ive mentioned that some form elements are rendered in
the “sidebox” divs. If instead i yield them in the “content” div
alongwith the rest of the form, everything works fine.

I figured maybe its because all the fields do not fall between the
form_for and end tags. So i tried something like this

/views/projects/new.html.erb
<% form_for @project do |f| %>
<%= f.error_messages %>
<% content_for :formfields do%>
<%=render :partial => “project”, :locals => {:f => f}%>


<%= f.submit “Save as Draft” %>


<% end %>
<% end %>

/views/layouts/application.html.erb

<%= yield%>

<%= controller.controller_name.capitalize %>

  <div class="content">
    <% flash.each do |key, msg| %>
          <%= content_tag :p, msg, :id => key, :class => 'flash'

%>
<% end %>
<%= yield :formfields%>


<div class="sidebar">

  <div class="sidebox">
    <%= yield :sidebox1 %>
  </div>

  <div class="sidebox">
    <%= yield :sidebox2 %>
  </div>

  <div class="sidebox">
    <%= yield :sidebox3 %>
  </div>
</div>
<div style="clear:both;"></div>

views/projects/_project.html.erb



<% content_for :sidebox1 do%>


<% end %>
<% content_for :sidebox2 do%>


<% end %>
<% content_for :sidebox3 do%>


<% end %># “…” representing form fields.

This way, the form fields are yielded into a div “content” which is
part of a larger div “wrapper” that yields the rest of the content
(including the form_for and end tags) (did this only for testing, do
not plan to structure my page this way). In any case, that did not
work either. The “Submit” button did nothing. The form was rendered
but clicking the Submit button did not submit anything.
Any suggestions?


#2

On Thu, Dec 4, 2008 at 10:26 PM, Ram removed_email_address@domain.invalid wrote:

I figured maybe its because all the fields do not fall between the
form_for and end tags.

No kidding. For all the “magic” in Rails, you still need to create
valid markup. :slight_smile:

The “Submit” button did nothing. The form was rendered
but clicking the Submit button did not submit anything.
Any suggestions?

Sure, validate your page; if you’re still having problems after that,
check the page for JS problems with FireBug. Or post a URL here.

HTH,

Hassan S. ------------------------ removed_email_address@domain.invalid