Last active
August 29, 2015 14:26
-
-
Save mnishiguchi/3aa6fa4a757efa59bef7 to your computer and use it in GitHub Desktop.
Ruby - 呼び出されているmethod名を検知してrefactoring ref: http://qiita.com/mnishiguchi/items/919a2d7903ac534852b6
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
| class OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
| def facebook | |
| user = User.from_omniauth(request.env["omniauth.auth"]) | |
| if user.persisted? | |
| set_flash_message(:notice, :success, kind: "Facebook") if is_navigational_format? | |
| sign_in_and_redirect user, event: :authentication | |
| else | |
| session["devise.user_attributes"] = user.attributes | |
| redirect_to new_user_registration_url | |
| end | |
| end | |
| def twitter | |
| user = User.from_omniauth(request.env["omniauth.auth"]) | |
| if user.persisted? | |
| set_flash_message(:notice, :success, kind: "Twitter") if is_navigational_format? | |
| sign_in_and_redirect user, event: :authentication | |
| else | |
| session["devise.user_attributes"] = user.attributes | |
| redirect_to new_user_registration_url | |
| end | |
| end | |
| end |
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
| class OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
| def callback_for_all_providers | |
| provider = __callee__.to_s # エイリアスメソッド名を読みこみ、文字列として利用。 | |
| user = User.from_omniauth(request.env["omniauth.auth"]) | |
| if user.persisted? | |
| sign_in_and_redirect user, event: :authentication | |
| set_flash_message(:notice, :success, kind: provider.capitalize) if is_navigational_format? | |
| else | |
| session["devise.user_attributes"] = user.attributes | |
| redirect_to new_user_registration_url | |
| end | |
| end | |
| alias_method :twitter, :callback_for_all_providers | |
| alias_method :facebook, :callback_for_all_providers | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment