Forum: Ruby on Rails Should all form elements for a form be in a single div?

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.
2dddec0f7717cae77ac6bceede6be5bc?d=identicon&s=25 Ram (Guest)
on 2008-12-05 07:27
(Received via mailing list)
My layout file is like this..

<div class = "wrapper">
     <div class = "main">
            <div class = "controller_name">
                       #printing the controller name
            </div>
            <div class = "content">
                     <%= yield%> #THIS IS WHERE THE NEW.HTML.ERB IS
RENDERED
            </div>
      </div>
      <div class ="sidebar">
               <div class = "sidebox">
                          <%= yield :sidebox_1%>#SOME FORM ELEMENT ARE
RENDERED IN HERE
                </div>
                <div class = "sidebox">
                          <%= yield :sidebox_2%>#SOME FORM ELEMENT ARE
RENDERED IN HERE
                </div>
       </div>
</div>

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}%>
      <p>
       <%= f.submit "Save as Draft" %>
    </p>
  <% end %>
<% end %>

/views/layouts/application.html.erb

 <div class="wrapper">
    <%= yield%>
    <div class="main">
      <div class="controller_name">
        <h1><%= controller.controller_name.capitalize %></h1>
      </div>

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

    <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>
  </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?
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2008-12-05 08:01
(Received via mailing list)
On Thu, Dec 4, 2008 at 10:26 PM, Ram <yourstruly.vinay@gmail.com> 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. :-)

> 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 Schroeder ------------------------ hassan.schroeder@gmail.com
This topic is locked and can not be replied to.