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" %>
           <%= f.select "lesson_icon", options_for_select([ "ico-03",
"ico-04","ico-05","ico-06" ])%></br></br>
           <div>
             <p style="display:none"><%=hh=0%></p>
            <%= f.fields_for :sublessons do |sublesson_a| %>

            <div class="delete-subtitle-<%=hh%>" style="padding-bottom:
25px;">
               <%= sublesson_a.label :sublesson_name, "Subtitle 1"
%></br>
               <%= sublesson_a.text_field :sublesson_name, class:
"form-control delete-sublesson-field-#{hh}" %></br>
               <%= sublesson_a.label :sublesson_content, "Content"
%></br>
               <%=sublesson_a.text_area 'sublesson_content', rows: 3,
class: "form-control delete-sublesson-content-#{hh}"%></br>
               <%= sublesson_a.label :sublesson_video_link, "Video link"
%><br>
               <%= 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
Sublesson</a>
               <p style="display:none"><%= hh=hh+1%></p>
            </div>

           <%end%>
          </div>

         <%= 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?

--
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1ab8e284800180043a518cdd31c0e530%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Javix at Aug 20, 2014 at 7:56 am

    On Wednesday, August 20, 2014 8:57:49 AM UTC+2, Ruby-Forum.com User wrote:
    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" %>
    <%= f.select "lesson_icon", options_for_select([ "ico-03",
    "ico-04","ico-05","ico-06" ])%></br></br>
    <div>
    <p style="display:none"><%=hh=0%></p>
    <%= f.fields_for :sublessons do |sublesson_a| %>

    <div class="delete-subtitle-<%=hh%>" style="padding-bottom:
    25px;">
    <%= sublesson_a.label :sublesson_name, "Subtitle 1"
    %></br>
    <%= sublesson_a.text_field :sublesson_name, class:
    "form-control delete-sublesson-field-#{hh}" %></br>
    <%= sublesson_a.label :sublesson_content, "Content"
    %></br>
    <%=sublesson_a.text_area 'sublesson_content', rows: 3,
    class: "form-control delete-sublesson-content-#{hh}"%></br>
    <%= sublesson_a.label :sublesson_video_link, "Video link"
    %><br>
    <%= 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
    Sublesson</a>
    <p style="display:none"><%= hh=hh+1%></p>
    </div>

    <%end%>
    </div>

    <%= 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?

    --
    Posted via http://www.ruby-forum.com/.
    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

    --
    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 rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6da9f0e4-eb03-49b8-8993-760327703530%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedAug 20, '14 at 6:57a
activeAug 20, '14 at 7:56a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Javix: 1 post Turcu Marius: 1 post

People

Translate

site design / logo © 2021 Grokbase