Hello,
I'm wrestling with something that should be very simple - specify a sidebar at the controller level. With layouts you can do this:
layout 'admin'
so I'd like to do the same for a sidebar, with something like this:
sidebar 'search'
I know I could specify the sidebar markup with content_for in the views, but I'd rather specify the sidebar at the controller level and not repeat code in (and clutter up) my views. I'd also like to be able to share sidebars between controllers.
At the moment I've got this in an initializer (a plugin seems like overkill for something so simple):
module Sidebar
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def sidebar(partial)
# neither of these two work...
@sidebar = partial
instance_variable_set('@sidebar', partial)
end
end
end
ActionController::Base.send(:include, Sidebar)
and then in my layout I'm trying
<%= render "shared/#{@sidebar}" %>
but to no avail...
Does anyone know what I'm doing wrong, or if indeed I'm going about this the right way at all? Any help is greatly appreciated!