On Aug 10, 2014, at 3:13 AM, Turcu Marius wrote:
> 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
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/1f56e1471a679746c29429b2bedc5df2%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/0B1F8E53-A1E3-433E-84DD-D75C70A9D7FD%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.