2013-04-20 271 views
0

爲所有頁面渲染動作(即「新聞」)的正確方式是什麼?我想是這樣的:在所有頁面上渲染動作

application.html.erb

<!DOCTYPE html> 
<html> 
... 
<div class="side"> 
    <%= render :template => 'news/index' %> 
</div> 
<div class="main"> 
    <%= yield %> 
</div> 
... 
</html> 

和news_controller.rb

class NewsController < ApplicationController 
    def index 
    @news_previews = News.news_for_quick_preview 
    render :layout => false 
    end 
end 

但現在它不工作。 @news_previews =>零

回答

2

在應用控制器添加before_filter :load_news

before_filter :load_news 
def load_news 
    @news_previews = News.news_for_quick_preview 
end