Skip to content

Instantly share code, notes, and snippets.

@linojon
Created April 3, 2009 17:22
Show Gist options
  • Save linojon/89844 to your computer and use it in GitHub Desktop.
Save linojon/89844 to your computer and use it in GitHub Desktop.
def menu_item( name, url_options={}, section_url=nil, &block)
#debugger
current = current_page?(url_options)
content = content_tag :li, :class => (current ? 'current' : nil) do
link_to(name, url_options) +
(block.nil? ? '' : capture(&block))
end
block.nil? ? concat(content, binding) : concat(content, block.binding)
end
# what to put for binding in concat(content, binding) ?
#====================
# case: simple block
<% menu_item 'Project', overview_project_path(current_project) do %>
Hello
<% end %>
=> works!
<li><a href="/projects/poetry_contest/overview">Project</a>
Hello
</li>
#====================
# case: no block
<% menu_item 'Project settings', edit_project_path(current_project) %>
=> ERROR
undefined local variable or method `_erbout' for #<ActionView::Base:0xaaad2c8>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment