Skip to content

Instantly share code, notes, and snippets.

@ichiban
Last active December 14, 2015 06:09
Show Gist options
  • Save ichiban/5040681 to your computer and use it in GitHub Desktop.
Save ichiban/5040681 to your computer and use it in GitHub Desktop.
Rubyの暗黒面が見えてきた
class DashboardController < ApplicationController
include TabsHelper
set_tab :dashboard
def index
end
end
<ul class="tabs">
<%= tab_for :dashboard, dashboard_path %>
<%= tab_for :hoge, hoge_path %>
<%= tab_for :fuga, fuga_path %>
</ul>
module TabsHelper
module Tabbable
def set_tab(tab)
TabsHelper.current_tab = tab
end
end
def self.included(base)
base.extend Tabbable
end
def self.current_tab=(tab)
@@current_tab = tab
end
def tab_for(tab, link, label=nil)
link_tag = link_to(label || tab.to_s.titleize, link)
content_tag(:li, link_tag, :class => ('active' if @@current_tab == tab))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment