2013-04-09 45 views
0

我有一個儀表板控制器,它具有online_user的操作。在視圖中,在儀表板下,我有一個部分_online_user.html.haml。其中,我試圖顯示在線登錄用戶。這裏的代碼:如何使用集合從另一個控制器渲染部分?

app/controllers/dashboard_controller 
    class DashboardController < ApplicationController 
     def online_user 
     @online_users = Profile.all(...) 
    end 
    end 

app/views/dashboard/_online_user.html.haml 


%li 
    = link_to profile_path(online_user) do 
    = online_user.name 
    %i.icon-picture 
    %i.icon-th-large 
    %i.icon-camera 
    %i.icon-facetime-video 
    %span.help-block 
     = online_user.try(:age) 
     - 
     = online_user.state.try(:name) 
     , 
     = online_user.country.try(:name) 

所有這一切都到位了,最後一件事就是在另一個視圖中渲染它。對?像這樣:

= render partial: "dashboard/online_user", collection: @online_users 

但是,當我這樣做時,我得到一個空白頁。什麼都沒有呈現。任何人的想法都非常感謝。

謝謝!

回答

0

你檢查@online_users是否包含任何東西,是不是空的? 此外,這可能有所幫助:

= render partial: "dashboard/online_user", collection: @online_users, as: :online_user 
+0

謝謝@ARjan。事實上,我確實檢查收集是否爲空。你的代碼示例很好,但在這種情況下它不適用於我。 – 2013-04-21 18:32:30

+0

也不適用於我 – brntsllvn 2015-07-21 00:35:15