views:

119

answers:

0

The following is outputting an empty unordered list. Why? Many thanks, Steven.

module BrowserHelper

  def project_browser_helper
    if @project || @controller.controller_name == "projects"
      content_tag(:div, content_tag(:ul, build_browser), :class => "browser")
    end
  end

  def build_browser
    @browser = []
    # a whole bunch of if/elsif/else statements
    # that call methods that add elements to @browser
    # including the following method
    # which is definitely called in this case
    show_an_all_projects_list_item
    @browser.map { |list_item| content_tag(:li, list_item['body'], :id => list_item['id'], :class => list_item['class']) }
  end

  def show_an_all_projects_list_item
    list_item = Hash.new
    list_item['body'] = ["All projects (", Project.find(:all).size.to_s, ")"].join
    list_item['class'] = "all_projects"
    list_item['id'] = "XXX"
    @browser << list_item
  end

end

I don't think it's a scope issue, as I get the same problem when I use $browser instead of @browser.

However, I am sure it relates to the value of @browser not persisting between methods, as when I copy the content of def show_an_all_projects_list_item into def build_browser just above the @browser.map statement, it works fine -- I get the expected <li> in my <ul>.