0

저는 Ruby on Rails의 초보자입니다. 그리고 저는 한국인입니다. 그래서 내 말은 거의 습관이 아냐. 내 질문은 ... 10 개의 데이터가있는 경우 첫 번째 줄에는 1 ~ 5 번째 데이터를, 두 번째 줄에는 6 ~ 10 번째 데이터를 넣고 싶다.Ruby on Rails를 사용하여 어떻게 데이터를 새로운 테이블 행에 넣을 수 있습니까?

like this

내가 시도를

   <table border height=300 width=300 align=center> 
       <thead> 
        <tr style="font size:20;"> 
        <th></th> 
        <th></th> 
        </tr> 
       </thead> 

       <tbody> 
        <% if current_user.samulham.nil? %> 
        <tr> 
         <% @samulham.each do |x| %> 
         <% if x.user_id.present?%> 
          <td><%= "X" %></td> 
         <% else %> 
          <td><%= link_to "#{x.lockernumber}", {:controller => "home", :action => "register", :cur_user => current_user.id, :cur_samulham => x.id}, method: :post %></td> 
         <% end %> 
         <% end %> 
        </tr> 
        <% end %> 
       </tbody> 
       </table> 

이 고려 주셔서 감사합니다이 코드를했습니다.

<tbody> 
         <% if current_user.samulham.nil? %> 
         <tr> 
          <% @samulham.first(5)each do |x| %> 
          <% if x.user_id.present?%> 
           <td><%= "X" %></td> 
          <% else %> 
           <td><%= link_to "#{x.lockernumber}", {:controller => "home", :action => "register", :cur_user => current_user.id, :cur_samulham => x.id}, method: :post %></td> 
          <% end %> 
          <% end %> 
         </tr> 
         <tr> 
          <% @samulham.last(5)each do |x| %> 
          <% if x.user_id.present?%> 
           <td><%= "X" %></td> 
          <% else %> 
           <td><%= link_to "#{x.lockernumber}", {:controller => "home", :action => "register", :cur_user => current_user.id, :cur_samulham => x.id}, method: :post %></td> 
          <% end %> 
          <% end %> 
         </tr> 
         <% end %> 
    </tbody> 

편집 : : : 데이터 세트의 크기는 항상 10

답변

1

경우는 다음과 같이, 그것은 하드 코딩 뭔가를 할 수 있지만 싶지는 일반적인 5 개 기록의 그룹에 대해한다면, 당신은 할 수

@samulham.in_groups_of(5).each do |group| 
         <tr> 
          <% group.each do |x| %> 
          <% if x.user_id.present?%> 
           <td><%= "X" %></td> 
          <% else %> 
           <td><%= link_to "#{x.lockernumber}", {:controller => "home", :action => "register", :cur_user => current_user.id, :cur_samulham => x.id}, method: :post %></td> 
          <% end %> 
          <% end %> 
         </tr> 
end 
+0

답장을 보내 주셔서 감사합니다. 하지만, 내 데이터 세트 크기는 일반적으로 10 이상입니다 ... 난 그냥 라인에 5 데이터를 설정하고 싶습니다. –

+0

@SunHuKim I 솔루션을 구성하는 데 도움이되는 게시물을 편집했습니다. 희망이 당신을 도울 것입니다 –

+0

그것은 정말 도움이 !! 고마워요! –