Commit f9449c10

mo khan <mo@mokhan.ca>
2013-06-05 04:34:49
load categories in a before filter
1 parent 838f2a9
Changed files (2)
app/controllers/application_controller.rb
@@ -1,6 +1,7 @@
 class ApplicationController < ActionController::Base
   protect_from_forgery
   before_filter :profile_application
+  before_filter :load_categories
 
   private
 
@@ -11,4 +12,8 @@ class ApplicationController < ActionController::Base
   def profile_application
     Rack::MiniProfiler.authorize_request unless ENV['PROFILE_APPLICATION'].blank?
   end
+
+  def load_categories
+    @categories = Category.all
+  end
 end
app/views/layouts/_header.html.erb
@@ -19,7 +19,7 @@
           <li class="dropdown">
             <a href="#" class="dropdown-toggle" data-toggle="dropdown">Categories<b class="caret"></b></a>
             <ul class="dropdown-menu">
-              <% Category.all.each do |category| %>
+              <% @categories.each do |category| %>
                 <li><a href="/categories/<%= category.slug %>"><%= category.name %></a></li>
               <% end %>
             </ul>