2015-04-26 37 views
0

我已經渲染了一個局部圖,它也在其中一個選項卡面板中加載了用戶最新帖子。用當地渲染局部圖

 <div role="tabpanel" class="tab-pane" id="updates_panel"> 
     <%= render :partial => "pages/update_panel", :locals => { :post => @user.latest_post } %> 
     </div> 

首先,方法latest_post是顯示用戶「Last or Latest Post」。

def latest_post 
    posts.order(:created_at => :desc).first 
end 

但現在我意識到我需要顯示所有帖子降序,我似乎無法得到這個權利。

回答

1

創建像​​另一種方法,

def latest_posts 
    posts.order(:created_at => :desc) 
end 

def latest_post 
    latest_posts.first 
end 

現在你帕塔爾使用,

<%= render :partial => "pages/update_panel", :locals => { :post => @user.latest_post, :posts => @user.latest_posts } %> 
+0

好像它的工作,但還沒有標籤面板下我仍然只顯示最新帖子,其餘的職位並沒有跟隨。 –