2016-05-04 33 views
0

いくつかのレコードとチェックボックスがある単純なフォームを作成しています。今、チェックボックスをオンにすると、最初の2つのレコードが非表示になります。チェックボックスが選択されている場合はレコードを表示

これは私のコントローラである:

def galleryhome 
    @gallery_photos = GalleryPhoto.where(gallery_id: params[:id]) 
end 

は、これが私の見解です:

<div class="checkbox"> 
    <input type="checkbox" name="remember" id="HideRecord"> 
    <label for="remember" class="optional">Hide photos in albums</label> 
    </div> 
</div> 
<div class="all-photo"> <!--start-photo-view--> 
    <%= hidden_field_tag "Value"%> 
    <% @gallery_photos.each do |gallery_photo| %> 
    <ul class="photos-view"> 
    <li class="photo-tile"> 
     <div class="inside-img"><%= image_tag gallery_photo.photo.url%></div> 
     <div class="inside-img-open"> 
     <a data-target="#viewlarge-Img" data-toggle="modal" href="#" class="fa fa-search" ></a> 
     </div> 
     <div class="photo-name"><%= gallery_photo.photo_file_name%></div> 
    </li> 
    </ul> 
    <% end %> 
</div> 

誰も私を助けてくださいことはできますか?

答えて

0
$('#HideRecord').click(function() { 
    if(document.getElementById('HideRecord').checked) { 
     $("ul li:nth-child(1)").hide(); 
     $("ul li:nth-child(2)").hide(); 
    } else { 
     $("ul li:nth-child(1)").show(); 
     $("ul li:nth-child(2)").show(); 
    } 
}); 
+0

をたくさん@Emuありがとう。しかし、それはすべての記録を隠している。 – Vishal

0

あなたは使用してjQueryを使ってそれを行うことができます。

$(document).ready(function() { 
    $("#HideRecord").click(function() { 
    if (this.checked) { 
     $(".photos-view").slice(0, 2).hide(); #Edited changes 
    } 
    }); 
}); 
+0

Thanx Gaurav。しかし、それはすべてのレコードを隠しています。 – Vishal

関連する問題