Ruby on Rails HTML problem

I have a form like this.. <div style="padding:13px">   <%= form_for @lesson do |f| %>      <%= f.label :lesson_name, "Lesson title" %></br>      <%= f.text_field :lesson_name, class: "form-control" %></br>      <%= f.label :lesson_icon, "Choise icon" %>      <%= f.select "lesson_icon", options_for_select([ "ico-03", "ico-04","ico-05","ico-06" ])%></br></br>

        <div>          <%= f.fields_for :sublessons do |sublesson_a| %>          <div class="add_new_subtitle">          <%= sublesson_a.label :sublesson_name, "Subtitle 1" %></br>          <%= sublesson_a.text_field :sublesson_name, class: "form-control" %></br>          <%= sublesson_a.label :sublesson_content, "Content" %></br>          <%=sublesson_a.text_area 'sublesson_content', rows: 3, class: 'form-control'%></br>          <%= sublesson_a.label :sublesson_video_link, "Video link" %><br>             <%= sublesson_a.text_field :sublesson_video_link, class: "form-control" %></br>        </div>   </div>    <%end%> <a href="javascript:;" style="float:right" class="btn btn-primary" id="addNewTag">Add Sublesson</a>   <%= f.submit "Submit", class: "btn btn-primary" %>   <% end %>

In controller i have...(because i want 51 sublessons fields) def new_lesson     @lesson=Lesson.new     51.times{@lesson.sublessons.build} end

The problem is in html the sublessons fields look like this.... <div id="main" class="clearfix" style="overflow: hidden">   <br> <div style="padding:13px"> </div> <div style="padding:13px"> <form id="new_lesson" class="new_lesson" method="post" action="/lessons" accept-charset="UTF-8"> <div style="display:none"> <label for="lesson_lesson_name">Lesson title</label> <br> <input id="lesson_lesson_name" class="form-control" type="text" name="lesson[lesson_name]"> <br> <label for="lesson_lesson_icon">Choise icon</label> <select id="lesson_lesson_icon" name="lesson[lesson_icon]"> <br> <br> <div> <div class=""> </form> </div> <div class=""> </div> <div class=""> </div> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle">

This went i watch with firebug but when i see the source of the face everything looks fine....I attach also a printscreen...Please help

Attachments: http://www.ruby-forum.com/attachment/9972/Capture.JPG

This looks like an “invalid markup” issue. At the top of the section you’ve got:

<%= f.fields_for :sublessons do |sublesson_a| %>

but at the bottom you’ve got

<% end %>

So the first time around the loop, the second there closes the surrounding

(the one before f.fields_for). On subsequent iterations, the
is invalid (the next enclosing element is a tag, not a
) but most browsers will try to muddle through, causing weird rendering.

–Matt Jones

I have a form like this.. <div style="padding:13px"> <%= form_for @lesson do |f| %>     <%= f.label :lesson_name, "Lesson title" %></br>     <%= f.text_field :lesson_name, class: "form-control" %></br>     <%= f.label :lesson_icon, "Choise icon" %>     <%= f.select "lesson_icon", options_for_select([ "ico-03", "ico-04","ico-05","ico-06" ])%></br></br>

       <div>         <%= f.fields_for :sublessons do |sublesson_a| %>         <div class="add_new_subtitle">         <%= sublesson_a.label :sublesson_name, "Subtitle 1" %></br>         <%= sublesson_a.text_field :sublesson_name, class: "form-control" %></br>         <%= sublesson_a.label :sublesson_content, "Content" %></br>         <%=sublesson_a.text_area 'sublesson_content', rows: 3, class: 'form-control'%></br>         <%= sublesson_a.label :sublesson_video_link, "Video link" %><br>            <%= sublesson_a.text_field :sublesson_video_link, class: "form-control" %></br>       </div> </div>   <%end%> <a href="javascript:;" style="float:right" class="btn btn-primary" id="addNewTag">Add Sublesson</a> <%= f.submit "Submit", class: "btn btn-primary" %> <% end %>

In controller i have...(because i want 51 sublessons fields) def new_lesson    @lesson=Lesson.new    51.times{@lesson.sublessons.build} end

The problem is in html the sublessons fields look like this.... <div id="main" class="clearfix" style="overflow: hidden"> <br> <div style="padding:13px"> </div> <div style="padding:13px"> <form id="new_lesson" class="new_lesson" method="post" action="/lessons" accept-charset="UTF-8"> <div style="display:none"> <label for="lesson_lesson_name">Lesson title</label> <br> <input id="lesson_lesson_name" class="form-control" type="text" name="lesson[lesson_name]"> <br> <label for="lesson_lesson_icon">Choise icon</label> <select id="lesson_lesson_icon" name="lesson[lesson_icon]"> <br> <br> <div> <div class=""> </form> </div> <div class=""> </div> <div class=""> </div> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle"> <div class="add_new_subtitle">

This went i watch with firebug but when i see the source of the face everything looks fine....I attach also a printscreen...Please help

Attachments: http://www.ruby-forum.com/attachment/9972/Capture.JPG

Are you trying to build a nested form? There's a Railscast abut that, and it's also covered in the Rails Guides, I think. The thing is you cannot nest a form inside another form -- that's just basic HTML rules, nothing specific to Rails. To make a nested form, you need to declare it as such in your view. I see that you have a relationship set up between a lesson and a sub lesson, so you need to declare in that relationship that the lesson accepts_nested_attributes_for the sub lessons. Then your lesson form can contain sub lesson fields, and the whole thing will be submitted and processed in one action.

Walter

walter thanks but i have you write....mat, you have right, you save my day...i was watched that code 2 hours and i don't figure out....Thanks all for trying to help me:)