Web サイトで omniauth-twitter を使用しようとしていますが、twitter ログインをクリックするたびにこのエラーが発生します
undefined method `persisted?' for []
omniauth_callbacks_controller.rb ファイル...
def twitter
# You need to implement the method below in your model
@user = User.find_for_twitter_oauth(request.env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Twitter"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.twitter_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
User.rb ファイル...
def self.find_for_twitter_oauth(access_token, signed_in_resource=nil)
data = access_token.extra.raw_info
if user = User.where(:email => data.email)
user
else # Create a user with a stub password.
User.create!(:name => data.name, :email => data.email, :password => Devise.friendly_token[0,20])
end
end
何か案が?