2011-01-06 69 views

回答

2

两个解决方案:

  • 使用<%= Post.all.count %>在布局中。
  • 在加载变量的ApplicationController中添加一个before_filter

    class ApplicationController < ActionController::Base 
        before_filter :load_layout_variables 
    
    protected 
        def load_layout_variables 
        @posts = Post.all.count 
        end 
    end 
    
+0

大。有效!我选择了第一个解决方案 – daniel 2011-01-06 13:40:41

相关问题