Forum: Ruby on Rails Edit form problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A551dd246cb624b7fd6a78d5ccee835d?d=identicon&s=25 Turcu Marius (mariusturcu)
on 2014-08-20 08:55
I have this form
 <%= 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" %>
          <%= "lesson_icon", options_for_select([ "ico-03",
"ico-04","ico-05","ico-06" ])%></br></br>
            <p style="display:none"><%=hh=0%></p>
           <%= f.fields_for :sublessons do |sublesson_a| %>

           <div class="delete-subtitle-<%=hh%>" style="padding-bottom:
              <%= sublesson_a.label :sublesson_name, "Subtitle 1"
              <%= sublesson_a.text_field :sublesson_name, class:
"form-control delete-sublesson-field-#{hh}" %></br>
              <%= sublesson_a.label :sublesson_content, "Content"
              <%=sublesson_a.text_area 'sublesson_content', rows: 3,
class: "form-control delete-sublesson-content-#{hh}"%></br>
              <%= sublesson_a.label :sublesson_video_link, "Video link"
              <%= sublesson_a.text_field :sublesson_video_link, class:
"form-control delete-sublesson-video-#{hh}" %></br>
              <a   style="float:right" class="btn btn-primary"
id="remove_sublesson" onclick="remove_sublesson(<%=hh%>)">Delete
              <p style="display:none"><%= hh=hh+1%></p>


        <%= f.submit "Submit", class: "btn btn-primary" %>
        <a   class="btn btn-primary" id="addNewTag"
onclick="add_sublesson()">Add Sublesson</a>

      <% end %>

This is a form for edit....How can i test if :sublessons is empty?
F7141e066d691d7f18765c1ea6389b18?d=identicon&s=25 Serguei Cambour (javix)
on 2014-08-20 09:57
(Received via mailing list)
On Wednesday, August 20, 2014 8:57:49 AM UTC+2, User
>            <%= f.fields_for :sublessons do |sublesson_a| %>
> class: "form-control delete-sublesson-content-#{hh}"%></br>
>           <%end%>
> --
> Posted via

I suppose that your lesson 'has_many' sublessons. In this case you can
check it as follows:

if @lesson.sublessons.any?

It returns true if the collection is not empty
This topic is locked and can not be replied to.