-
Notifications
You must be signed in to change notification settings - Fork 13
Navigations
Leather has a helper method that lets you generate Bootstrap navbars and navigation lists. For example, you can render a navbar with the following code:
= navbar "Leather", root_url, container_mode: :with, class: "navbar-inverse" do
= nav_list do
= dropdown_nav_item 'Lorem', '#' do
= nav_item 'Ipsum', '#'
= nav_item 'Dolor', '#'
= nav_item 'Sit', '#'
= nav_item 'Home', '#'
= nav_item 'Dolor', '#'
= nav_item 'Sit', '#'
= nav_list class: 'navbar-right' do
- if user_signed_in?
= nav_item 'Sign Out', destroy_user_session_path, method: :delete
- else
= nav_item 'Sign In', new_user_session_path
= nav_item 'Sign Up', new_user_registration_path`
With a little extra setup, you can manage the "active" nav_item easily. First, in your applicaiton controller, add this:
before_action :setup_current_navs
private
def setup_current_navs
@current_navs = {}
end
This sets up a hash that will hold your navigation lists and the active item. When you generate a nav_item or a dropdown_nav_item, you can tell it which navigation list and item that link corresponds to:
= nav_item 'Home', '#', nav_id: [:main, "home"]
The final step is to fill in the @current_navs hash in your other controllers. In this example, we're saying that this link should get the "active" class when the current nav for the :main navigation list is set to "home". So in our home_controller (in a before_action or within a specific action), we could do this:
@current_navs[:main] = "home"