Last active
August 29, 2015 14:27
-
-
Save yamaaki/0230b9c7570127164f68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| module ApplicationHelper | |
| def nav_header(key) | |
| active = false | |
| if key == :profile | |
| active = true if is_nav_active?(:edit_profile) | |
| active = true if is_nav_active?(:sign_out) | |
| text = 'Profile' | |
| end | |
| if active | |
| link_to text, '#', class: 'collapsible-header waves-effect waves-teal active' | |
| else | |
| link_to text, '#', class: 'collapsible-header waves-effect waves-teal' | |
| end | |
| end | |
| def nav_header_li(key) | |
| active = false | |
| active = true if is_nav_active?(key) | |
| if key == :sign_in | |
| text = 'Sign in' | |
| path = new_member_session_path | |
| end | |
| if key == :edit_profile | |
| return true if current_page?(edit_member_registration_path) | |
| return true if request.fullpath == '/member/members' && request.method == 'POST' | |
| end | |
| if key == :sign_out | |
| return true if request.fullpath == '/member/members/sign_out' | |
| end | |
| if active | |
| content_tag :li, class: 'active' do | |
| link_to text, path, class: 'waves-effect waves-teal' | |
| end | |
| else | |
| content_tag :li do | |
| link_to text, path, class: 'waves-effect waves-teal' | |
| end | |
| end | |
| end | |
| def is_nav_active?(key) | |
| if key == :sign_in | |
| return true if current_page?(new_member_session_path) | |
| return true if request.fullpath == '/member/members/sign_in' | |
| end | |
| if key == :edit_profile | |
| return true if current_page?(edit_member_registration_path) | |
| return true if request.fullpath == '/member/members' && request.method == 'POST' | |
| end | |
| if key == :sign_out | |
| return true if request.fullpath == '/member/members/sign_out' | |
| end | |
| return false | |
| end | |
| def nav_li(key) | |
| active = false | |
| active = true if is_nav_active?(key) | |
| if key == :edit_profile | |
| text = 'Edit' | |
| path = edit_member_registration_path | |
| method ='GET' | |
| end | |
| if key == :sign_out | |
| text = 'Sign out' | |
| path = destroy_member_session_path | |
| method = 'DELETE' | |
| end | |
| if active | |
| content_tag :li, class: 'active' do | |
| if method && method != 'GET' | |
| link_to text, path, method: method | |
| else | |
| link_to text, path | |
| end | |
| end | |
| else | |
| content_tag :li do | |
| if method && method != 'GET' | |
| link_to text, path, method: method | |
| else | |
| link_to text, path | |
| end | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment