ruby on rails logic for a partial in a layout

layout, partial-views, ruby-on-rails

Solution

Maybe there's a better way to do this, but if it's on most or all pages you could create a before_filter on your ApplicationController. You'll have to call `skip_before_filter` on the controllers/actions that don't need the data.

class ApplicationController < ActionController::Base
  before_filter :load_sidebar_data

protected
  def load_sidebar_data

  end
end

If you don't need it on most pages you'd still put the method in the ApplicationController, you'd just add the before filter where you need it.

Problem

I have a sidebar that is going to have some logic in it, similar to how a view talks to a controller. Where do I put the logic in for the partial? Do I create a new controller for the layout and put it in there? The layout is for logged in users, like a dashboard. The dashboard is going to have a sidebar that shows the same dynamic content on every page. Since it's being shown on every page I want to put it in a partial. I'm just confused on where to put the find's and all that information.

Original source