2013-09-24 48 views
1

我能夠爲提交數據的用戶顯示我的表中的信息。我似乎無法設置如何顯示錶中的所有用戶信息。在視圖中顯示來自表列的數據

index.html.erb:

#This gives undefined local variable or method 'bio'. bio.content works on the user page if signed in and shows data from the user only. 

<%= bio.content.all %> 

bio_controller.rb:

  def show 
      @bio= User.all 
     end 

user_controller.rb:

def show 
    @bio = current_user.bio.build 

有人可以幫告訴我究竟是什麼我失蹤使我可以顯示數據庫中的所有生物信息,而不是僅允許顯示登錄的數據從他們的個人資料中選擇

回答

2

在視圖中需要@bio.content.all。你可能想用一些HTML來構造它:

if @bio 
    @bio.content.all.each do |b| 
     <!-- some HTML to show the `b` record --> 
    end 
end 
+0

這給了一個未定義的方法'內容'爲零。內容是我的數據庫表名稱,我必須在def show下的bio控制器中定義它嗎?今天早上我已經嘗試了幾條不同的路線。 – xps15z

+0

問題也許在我的路線中。會調整一下,看看我能否找到解決方案。 – xps15z

+0

@ xps15z你的帖子表明你設置了'@ bio'。如果有可能它是空的,那麼你可以做一個檢查無。如果在空或不空時還有其他「業務邏輯」,則需要更詳細地回答這個問題。現在,你只能看到一小段代碼。 :) – lurker

相關問題