Skip to content

danielvlopes/menu_builder

Repository files navigation

menu_builder

A simple helper + controller macro to make easier to highligh menu items based on actions (instead of urls)

Instalation

gem "menu_builder"

Usage

Controller

class DashboardController < ApplicationController
  menu_item :mydashboard
  ...
end

You can also change to menu item at action level instead of class level.

class DashboardController < ApplicationController
  menu_item :mydashboard

  def prices
    menu_item :prices
    ...
  end
end

And you can prepend or append just one item to the collection

class DashboardController < ApplicationController
  menu_item :mydashboard

  def prices
    append_menu_item :prices
    ...
  end
end

View

ERB code

<%= menu(:id=>"mainMenu", :class=>"menu") do |m| %>
  <%= m.account 'Account', account_path, :style => 'float: right' %>
  <%= m.users 'Users', users_path, :style => 'float: right' %>
  <%= m.mydashboard 'Dashboard', '/' %>
  <%= m.projects 'Projects', projects_path %>
<% end %>

HTML Result

<ul id="mainMenu" class="menu">
  <li><a href="/accounts">Account</a></li>
  <li><a href="/users">Users</a></li>
  <li><a href="/" class="current">Dashboard</a></li>
  <li><a href="/projects">Projects</a></li>
</ul>

Blocks for content

You can also pass blocks:

<%= menu do |m| %>
  <% m.account account_path do %>
    <%= image_tag "icon.jpg" /> Accounts
  <% end %>
  <%= m.users "Users", users_path %>
  <%= m.posts "Posts", posts_path %>
<% end %>

About

Simple helper for menus and tabs in Rails

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages