Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

semantic menu can't use current_page? b/c it doesn't have a reference to the controller instance #1

Closed
ajsharp opened this issue Apr 24, 2010 · 2 comments

Comments

@ajsharp
Copy link
Contributor

ajsharp commented Apr 24, 2010

This is due to how the controller instance is passed into the SemanticMenu intializer. Still, to get this instance to each
module MenuHelper
def semantic_menu(opts={}, &block)
# controller is not available in this context, but @controller is
SemanticMenu.new(opts, &block).to_s(controller)
end
end

#...
ActionView::Base.send :include, MenuHelper

Additionally, we need to fix how the child menu items are being passed a controller instance.

class SemanticMenu < MenuItem

  def initialize(opts={},&block)
    @opts = {:class => 'menu'}.merge opts
    @level = 0
    @children = []

    yield self if block_given?
  end

  def to_s(controller=nil)
    @controller = controller
    # we need to pass the @controller instance to each child as well
    content_tag(:ul, @children.collect(&:to_s).join, @opts)
  end
end
@ajsharp
Copy link
Contributor Author

ajsharp commented Apr 24, 2010

I've forked, patched, and submitted a pull request. Here's the patch commit: http://github.com/ajsharp/semantic-menu/commit/40f6be8f168061931b541c44502ab06513588bc0

Thanks for this plugin, I LOVE the simplicity of it!

@danielharan
Copy link
Owner

reverted changes that caused this

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants