Last active
February 14, 2018 00:44
-
-
Save igmarin/4b0e380a446740e7530f31263be9cd19 to your computer and use it in GitHub Desktop.
method_with several links
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
def login_form_links | |
links = [sign_in, devise_registration, password_recovery, confirmation_instructions, unlock_email] | |
if devise_mapping.omniauthable? | |
resource_class.omniauth_providers.each do |provider| | |
links << link_to(t('.sign_in_with_provider', provider: OmniAuth::Utils.camelize(provider)), omniauth_authorize_path(resource_name, provider)) | |
end | |
end | |
links.join(' ') | |
end | |
def login_link_to(title, link_route, klass = 'paragraph') | |
link_to(t(".#{title}"), link_route, class: klass) | |
end | |
def am_i_in?(name) | |
controller_name != name | |
end | |
def devise_registration | |
if devise_mapping.registerable? && am_i_in?('user_registrations') | |
login_link_to('sign_up', new_registration_path(resource_name)) | |
end | |
end | |
def confirmation_instructions | |
if devise_mapping.confirmable? && am_i_in?('confirmations') | |
login_link_to('didn_t_receive_confirmation_instructions', new_confirmation_path(resource_name)) | |
end | |
end | |
def password_recovery | |
if devise_mapping.recoverable? && am_i_in?('user_passwords') && am_i_in?('registrations') | |
login_link_to('forgot_your_password', new_password_path(resource_name)) | |
end | |
end | |
def sign_in | |
login_link_to('sign_in', new_session_path(resource_name)) if am_i_in?('user_sessions') | |
end | |
def unlock_email | |
if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && am_i_in?('unlocks') | |
login_link_to('didn_t_receive_unlock_instructions', new_unlock_path(resource_name)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment