簡體   English   中英

活動記錄不顯示表

[英]Active record is not display table

正如我在Active Record上工作一樣,我為Active Reocrd(例如Avg)處理不同的功能,求和和計數,因為它顯示正常,並且Chart,

但是有一件事讓我感到困惑,但我仍然無法正常工作,它應該工作正常,因為我無法像顯示所有數據列表一樣

 <table id="dttb" class="table table-hover">
     <thead>
         <tr>
             <th> full name </th>
         </tr>
     </thead>
     <tbody>
            <tbody>
              <% @user.each do |user| %>
                <tr>
                  <td><%= user.fullname %></td>
                </tr>
              <% end %>
            </tbody>
     </tbody>
 </table>

因為它應該繼續工作,因為錯誤一直顯示

nil:NilClass的未定義方法“ each”

當我查找信息時,其中大多數都被提及。每個操作都好像是我做錯了

<%= User.count(:user) %>

<%= column_chart User.group(:provider).count(:user) %>

並且似乎可以很好地用作查詢功能。

所以我再次嘗試了find_each

 <% User.find_each do |user| %>
      <tr>
        <td><%= puts user.fullname %></td>
      </tr>
    <% end %>

並且錯誤消失了,但是它不會顯示在數據上,並且顯示空白,除非我輸入“ link_to”,但它們會像

在此處輸入圖片說明

而且我把AdminController.rb

class AdminController < ApplicationController
  before_action :authenticate_user!

  def index
  @user = User.all 
  @tools = Tool.all 
  end
end

似乎我錯過了一些東西,我看過Google或stackover流,其中大多數答案與我編寫的這段代碼非常相同

更新:因為我能夠獲得一些數據,例如電話號碼或電子郵件

在此處輸入圖片說明

這是我寫的代碼

 <% User.find_each do |user| %>
 <tr>
     <td><%= link_to user.id, user  %></td>
     <td><%= link_to user.email, user %></td>
     <td><%= link_to user.created_at.strftime('%v'), user %></td>
     <td><%= link_to user.fullname, user  %></td>
     <td><%= link_to user.phone_number, user %></td>
 </tr>
 <% end %>

但應顯示全名,但不能顯示全名

在此處輸入圖片說明

在控制器中設置@user (或更好的@users ):

def index # or the actual action name
  @users = User.all # or User.order(:fullname)
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM