ruby on rails - How to setup restriction for view in a table tag? -


this code of view file. shows multiple columns table.

the restriction working columns multiple.

<table class="table table-responsive">     <tr>         <th>title</th>         <th>description</th>      <% obj.each |article| %>         <% if logged_in? && current_user == article.user %>             <th>edit</th>             <th>show</th>             <th>delete</th>             <th>created by</th>             <th>created at</th>             <th>updated at</th>         <% end %>      <% end %>     </tr>       <% obj.each |article| %>     <tr>     <td><%= article.title %></td>     <td><%= article.description %></td>     <% if logged_in? && current_user == article.user %>          <td><%= link_to "edit", edit_article_path(article), class: "btn btn-primary" %> </td>         <td><%= link_to "show", article_path(article), class: "btn btn-success" %></td>         <td><%= link_to "delete", article_path(article), method: :delete, data: {confirm: "are sure?"}, class: "btn btn-danger" %></td>          <td> <%= article.user.username if article.user %> </td>         <td> <%= time_ago_in_words(article.created_at) %> ago.</td>         <td> <%= time_ago_in_words(article.updated_at) %> ago.</td>         </tr>     <% end %>      <% end %> </table>  <%= link_to 'back', root_path, class: "btn btn-primary btn-lg" %> 

enter image description here

you're printing thead depending on value of obj, try leaving second iteration, print each tr, maybe like:

<% if logged_in? && current_user == article.user %>   <tr>     <th>edit</th>     <th>show</th>     <th>delete</th>     <th>created by</th>     <th>created at</th>     <th>updated at</th>   </tr>    <tbody>     <% obj.each |article| %>       <tr>         <td><%= article.title %></td>         <td><%= article.description %></td>         <% if logged_in? && current_user == article.user %>           <td><%= link_to "edit", edit_article_path(article), class: "btn btn-primary" %> </td>           <td><%= link_to "show", article_path(article), class: "btn btn-success" %></td>           <td><%= link_to "delete", article_path(article), method: :delete, data: {confirm: "are sure?"}, class: "btn btn-danger" %></td>           <td> <%= article.user.username if article.user %> </td>           <td> <%= time_ago_in_words(article.created_at) %> ago.</td>           <td> <%= time_ago_in_words(article.updated_at) %> ago.</td>         <% end %>       </tr>     <% end %>   </tbody> <% end %> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -