Hi,
I’m trying to write a sidebar menu with dynamic menus, and to do so I
would like to define a list of menus to display within my sidebar
component controller code and pass that list to the component display
view, like so:
menu_controller.rb
class Sidebar::MenuController < ActionController::Base
uses_component_template_root
@menus = %w{admin user help}
def display
@display_menu = params[:menu]
render(:layout => false)
end
end
menu/display.rhtml
When trying to run display.rhtml, I get errors saying @menu == nil
instead of Array. Now if I replace the display @menus loop with this:
<% (%w{admin user help}).each do |menu| %>
it works as expected.
I’ve tried putting @menus both within the display method and outside it
in the class definition. Am I not understanding the component concept
correctly? The Rails book demonstrates component controller classes
passing instance variables to the views (pp. 376-377, look for get_links
and @links) so what am I missing?
TYVMIA,
- Matt