1
senario 내가 App_clients라는 이름의 모델을 가지고 있으며, 트위터와 페이스 북라는 이름의 모델은 모두 그것으로부터 상속 :Rails 4에서 인스턴스를 동적으로 생성 할 수 있습니까?
Model App
def initialize(provider,access_token)
end
Model Twitter < App
def initialize(provider, access_token)
@client = Twitter::API.new(access_token)
end
Model Facebook < App
def initialize(provider, access_token)
@client = Facebook::API.new(access_token)
end
내 질문은 그게를 만들 수 Apps_controller 또는 모델 앱의 방법을 가질 가능성이있다 params [: provider]에 따라 app 클라이언트의 인스턴스가 있습니까? 많은 if 또는 elsif를 추가하여 클라이언트를 결정할 필요가 없습니다.
BTW, 전 omniauth를 사용하여 트위터와 페이스 북의 인증을 통합했습니다.
매우 도움을 주셔서 감사합니다.
정말 고맙습니다! 잘 작동한다!! – Perpherior