내 Rails 앱에서 사용자 및 인증 데이터를 처리하기위한 테이블이 user
및 authorization
입니다.권한 부여 후 Omniauth 콜백 처리
NoMethodError at /users/auth/twitter/callback
undefined method `authorizations' for #<Class:0xbdc8100>
어느 쪽에서, 내가 잘못 가서 어떻게 않았다 나는 트위터로 리디렉션하지만 내 응용 프로그램에 반환 한 후,이 같은 오류를 제공, 가입 트위터를 사용하기 위해 고안 및 Omniauth 모두를 설정 이 문제가 해결 되었습니까? 여기
되어 관련 부품 : omniauth_callbacks_controller.rb
:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def all
user = User.authorizations.from_auth(auth_hash)
if user.persisted?
flash.notice = "Signed in!"
sign_in_and_redirect user
else
session["devise.user_attributes"] = user.attributes
redirect_to new_user_registration_url
end
end
alias_method :twitter, :all
protected
def auth_hash
request.env['omniauth.auth']
end
end
authorization.rb
:
class Authorization < ActiveRecord::Base
attr_accessible :uid, :provider
belongs_to :user
def self.from_auth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
end
end
user.rb
:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:twitter, :facebook]
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :name
# attr_accessible :title, :body
has_many :authorizations, dependent: :destroy
end
User.authorizations.from_auth 대신 Authorization.from_auth를 사용해야한다고 생각합니다. –
이전에 'Authorization.from_auth'을 시도했지만 작동하지 않았습니다. – ekremkaraca