在所有页面上渲染操作

时间:2013-04-20 09:36:02

标签: ruby-on-rails

为所有网页呈现操作(即“新闻”)的正确方法是什么?我想要这样的东西:

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 =&gt;零

1 个答案:

答案 0 :(得分:2)

在应用程序控制器中添加before_filter :load_news

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