0

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

应用程序.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 => 无

4

1 回答 1

2

add before_filter :load_news in application controller

before_filter :load_news 
def load_news
  @news_previews = News.news_for_quick_preview
end
于 2013-04-20T09:40:49.760 回答