Last active
November 17, 2016 23:45
-
-
Save MiguelSavignano/9aad18bff359389ead309ac722ee05c0 to your computer and use it in GitHub Desktop.
Tabs rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def link_tab(content, tab_name, options={}) | |
prefix_active = "active" | |
tab_name = tab_name.to_s | |
css_class = | |
if params[:tab].blank? | |
options[:default] ? prefix_active : nil | |
elsif params[:tab] == tab_name | |
prefix_active | |
end | |
link_to content, current_path({tab: tab_name}), class: css_class | |
end | |
def tab_view(tab_name, options={}) | |
tab_name = tab_name.to_s | |
show_tab = params[:tab].blank? ? options[:default] : params[:tab] == tab_name | |
if show_tab | |
yield | |
else | |
nil | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= link_tab "Tab1", :tab1, default: true %> | |
<%= link_tab "Tab2", :tab2 %> | |
<%= tab_view(:tab1, default:true) do %> | |
<%= render 'tab1' %> | |
<% end %> | |
<%= tab_view(:tab2) do %> | |
<%= render 'tab2' %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment