Module: DropdownHelper

Defined in:
app/helpers/dropdown_helper.rb

Instance Method Summary collapse

Instance Method Details

#activatable_li_tag(url, css_class = '', &block) ⇒ Object

li tag with the ‘active’ class added if the url is the current one. Good for navbar and dropdowns. Eg.:

<%= activatable_li_tag users_path do |url| %>
  <%= link_to "Users", url %>
<% end %>


10
11
12
13
# File 'app/helpers/dropdown_helper.rb', line 10

def activatable_li_tag(url, css_class = '', &block)
  css_class = current_page?(url) ? "active #{css_class}" : css_class
   :li, capture(url, &block), class: css_class
end

li tag with the ‘active’ class added if the url is the current one with a link inside it pointing to that url. Good for navbar and dropdowns. Eg.:

<%= activatable_li_tag_with_link "Users", users_path %>

Same as:

<%= activatable_li_tag users_path do |url| %>
  <%= link_to "Users", url %>
<% end %>


28
29
30
31
# File 'app/helpers/dropdown_helper.rb', line 28

def activatable_li_tag_with_link(title, url, options = {})
  options[:class] = current_page?(url) ? "active #{options[:class]}" : options[:class]
   :li, link_to(title, url, {class: 'nav-link', target: options[:target]}), options
end

#caret_tagObject



33
34
35
# File 'app/helpers/dropdown_helper.rb', line 33

def caret_tag
  (:span, '', class: 'caret')
end


45
46
47
48
49
# File 'app/helpers/dropdown_helper.rb', line 45

def dropdown_button(title, &block)
  link_to(h(title) + ' ' + caret_tag, '#',
          'data-toggle' => 'dropdown', class: 'btn dropdown-toggle') +
    (:ul, class: 'dropdown-menu', &block)
end


37
38
39
40
41
42
43
# File 'app/helpers/dropdown_helper.rb', line 37

def dropdown_menu(title, &block)
   :li, class: 'dropdown' do
    link_to(h(title) + ' ' + caret_tag, '#',
            'data-toggle' => 'dropdown', class: 'dropdown-toggle') +
      (:ul, class: 'dropdown-menu', &block)
  end
end