Ruby on Rails HTML problem

I have a form like this…

<%= form_for @lesson do |f| %> <%= f.label :lesson_name, "Lesson title" %> <%= f.text_field :lesson_name, class: "form-control" %> <%= f.label :lesson_icon, "Choise icon" %> <%= "lesson_icon", options_for_select([ "ico-03", "ico-04","ico-05","ico-06" ])%>
     <%= 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” %>
<%= sublesson_a.label :sublesson_content, “Content” %>
<%=sublesson_a.text_area ‘sublesson_content’, rows: 3, class:
<%= sublesson_a.label :sublesson_video_link, “Video link”

<%= sublesson_a.text_field :sublesson_video_link, class:
“form-control” %>

<%end%> Add Sublesson <%= f.submit "Submit", class: "btn btn-primary" %> <% end %>

In controller i have…(because i want 51 sublessons fields)
def new_lesson

The problem is in html the sublessons fields look like this…

Lesson title

Choise icon

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

On Sunday, 10 August 2014 03:14:31 UTC-4, User wrote:

        <%= sublesson_a.text_field :sublesson_video_link, class:

“form-control” %>


This looks like an “invalid markup” issue. At the top of the section

<%= 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
(the one before f.fields_for). On subsequent
is invalid (the next enclosing element is a tag, not a
) but most browsers will try to muddle through, causing weird rendering.

–Matt J.

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:)

On Aug 10, 2014, at 3:13 AM, Turcu M. wrote:

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

“form-control” %>

everything looks fine....I attach also a printscreen...Please help


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.