1

I'm working with Twitter and Facebook omni auth

I've this method that creates a user

    def self.find_or_create_from_auth_hash(auth_hash)
        user = where(provider: auth_hash[:provider], uid: auth_hash[:uid]).first_or_create
        user.update(
            name: auth_hash.info.name,
            profile_image: auth_hash.info.image,
            token: auth_hash.credentials.token,
            secret: auth_hash.credentials.secret,
            url: auth_hash.info.urls.Twitter,
            nickname: auth_hash.info.nickname
            )
        user
    end

How do I make it so that if provider is Twitter do

url: auth_hash.info.urls.Twitter,

But if provider is Facebook, do this instead

url: auth_hash.info.urls.Facebook,
Victor Yee
  • 151
  • 1
  • 14
  • The answers here may help: http://stackoverflow.com/questions/5349624/how-to-call-methods-dynamically-based-on-their-name – hexinpeter Oct 30 '15 at 05:00

1 Answers1

0

you can change the code like : url: auth_hash.info.urls.auth_hash[:provider]

auth_hash[:provider] either return Facebook OR Twitter

Rahul
  • 229
  • 2
  • 6