私はここでいくつかの解決策を見てきましたが、誰も私の問題に答えていません。私は、UserとDesignerの2つのモデルを生成するためにdeviseを使いました。そして、Omniauthを使ってこの2つのモデルを別々にサインイン/サインインする必要があります。現在、これは私が持っているものです。Devise + Omniauth複数のモデル
User.rb
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.user_name = auth.info.name
user.email = auth.info.email
user.password = "password"
user.skip_confirmation!
end
user_authentications_controller.rb
class UserAuthenticationsController < Devise::OmniauthCallbacksController
def create
begin
@user = User.from_omniauth(request.env['omniauth.auth'])
sign_in_and_redirect @user
#redirect_to root_url, notice: "Signed in!"
flash[:success] = "Welcome, #{@user.first_name}!"
UserMailer.welcome(@user).deliver_now
rescue
flash[:warning] = "There was an error while trying to authenticate you..."
end
end
end
designer.rb
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |designer|
designer.provider = auth.provider
designer.uid = auth.uid
designer.user_name = auth.info.name
designer.email = auth.info.email
designer.password = "password"
designer.skip_confirmation!
end
end
designer_authentication_controller.rb
DesignerAuthenticationsController < Devise::OmniauthCallbacksController
def create
begin
@designer = Designer.from_omniauth(request.env['omniauth.auth'])
sign_in_and_redirect @designer
#redirect_to root_url, notice: "Signed in!"
flash[:success] = "Welcome, #{@designer.first_name}!"
UserMailer.welcome(@designer).deliver_now
rescue
flash[:warning] = "There was an error while trying to authenticate you..."
end
end
end
routes.rbを
devise_scope :user do get "/auth/:provider/callback" => "user_authentications#create" end
devise_scope :designer do get "/auth/:provider/callback" => "designer_authentications#create" end
私の問題は、次のとおりです。
1)どんなにがどの私はサインアップページ、設計者やユーザーから、それがユーザーとして登録されます。両方のサインアップにuser_authentications_controllerを使用しているからです。どのようなアイデアをどのように私は彼らがサインアップページで呼び出すコントローラを決定させることができますか?
2)私は正しいやり方をしていますか、複数のモデルにサインアップする方法はありますか?
ありがとうございました。そして助けてください!