2017-01-17 15 views
0

Я получаю эту ошибку, и я не уверен, почему. Есть аналогичные проблемы, подобные этому, которые не могут решить мой случай.undefined метод `persisted? ' для true: TrueClass

  • может быть от user = User.where(:email => auth.info.email).first
  • может быть от where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
  • или даже на persisted? части в omniauth_controller

Что может быть возможные варианты или решения этой ошибки ?? Спасибо!! ^^

Omniauth_controller: где сохранились? ошибка имеет место.

def facebook 

    puts "1111111111 yayayay" 
    # raise request.env["omniauth.params"].inspect 

     user = User.from_omniauth((request.env["omniauth.auth"]), (request.env["omniauth.params"]), (request.remote_ip)) 

     if user.persisted? 
     puts "3333333 okayay" 
      sign_in_and_redirect @user, :event => :authentication 
      set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? 
     else 
     puts "wtf wtf wtf wtf wtf" 
      session["devise.facebook_data"] = request.env["omniauth.auth"] 
      redirect_to new_user_registration_url 

     end 
    end 

Модель пользователя, где я создать проверку полосы и facebook OmniAuth.

#gathering the info from social media when making an account. 
def self.from_omniauth(auth, auth_params, request) 

anonymous_username = "NewUser#{User.last.id + 100}" 
generated_password = Devise.friendly_token[0,20] 

user = User.where(:email => auth.info.email).first 

puts "auth params are #{auth_params}" 
puts "user type is #{auth_params["user_type"]}" 



if user 
    return user 
else 
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 
    user.confirmed_at = Time.now 
    user.fullname = auth.info.name 
    user.provider = auth.provider 
    user.user_type = auth_params["user_type"] 
    user.uid = auth.uid 
    user.username = anonymous_username 
    user.email = auth.info.email 
    if auth.info.image.present? 
    avatar_url = process_uri(auth.info.image) 
    user.avatar = URI.parse(avatar_url) 
    end 
    user.password = generated_password 
    user.save 
    user 
end 

#reviser account creation 
user = User.where(:email => auth.info.email).first 
puts "before the if #{user} and #{user.user_type}" 
if user.user_type == 'reviser' 
    puts 'this is reviser starting to create account' 
require "stripe" 
    email = auth.info.email 

    begin 

    Stripe.api_key = ENV['STRIPE_SECRET_KEY'] 

    account = Stripe::Account.create(
    { 
     :country => 'US', 
     :managed => true, 
     :tos_acceptance => { 
     :date => Time.now.to_i, 
     :ip => request 
     }, 
     :transfer_schedule => { 
     :interval => 'manual' 
     }, 
     :email => email, 

     :legal_entity => { 
      :type => 'individual' 
      } 

     } 
     ) 

    verification = Verification.create!(
     user_id: user.id, 
     country: 'US', 
     email: email, 
     terms_of_service: true 


     ) 


     puts "success!1: #{account.id}" 
     puts "success!4: #{account.keys.secret}" 
     puts "success!5: #{account.keys.publishable}" 
     verification.update_attributes account_id: account.id 





     rescue Stripe::InvalidRequestError => e 
     if e.message == "An account with this email already exists." 
     redirect_to stripe_path, alert: "An account with this email already exists." 
     else 
     puts "#{e.message}" 
     flash[:error]= e.message 
     end 

    rescue Stripe::AuthenticationError => e 
     redirect_to stripe_path, alert: "oops! Please let us know about this error! Please Try Again Later!" 
    # Authentication with Stripe's API failed 
    # (maybe you changed API keys recently) 
rescue Stripe::APIConnectionError => e 
    redirect_to stripe_path, alert: "oops! Something went wrong! Please Try Again!" 
    # Network communication with Stripe failed 
rescue Stripe::StripeError => e 
    redirect_to stripe_path, alert: "oops! Something went wrong! Please Try Again!" 
    # Display a very generic error to the user, and maybe send 
    # yourself an email 

end 
end 



end 
end 
+0

, когда '' создание учетной записи ''reviser', этот код будет выполнен. Я думаю, что у вас неправильный конец синтаксиса. проверьте один раз. – Sravan

+0

создание '#reviser account' - это всего лишь примечание, которое я оставил для организации, чтобы сообщить мне, когда началась создание учетной записи stripe. После создания пользователя для приложения –

ответ

2

Ваш метод from_omniauth возвращается верно из-за линии user.save. Возвратите a user в конце, как:

def self.from_omniauth(auth, auth_params, request) 

    anonymous_username = "NewUser#{User.last.id + 100}" 
    generated_password = Devise.friendly_token[0,20] 

    user = User.where(:email => auth.info.email).first 

    puts "auth params are #{auth_params}" 
    puts "user type is #{auth_params["user_type"]}" 



    if user 
    return user 
    else 
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user| 
     user.confirmed_at = Time.now 
     user.fullname = auth.info.name 
     user.provider = auth.provider 
     user.user_type = auth_params["user_type"] 
     user.uid = auth.uid 
     user.username = anonymous_username 
     user.email = auth.info.email 
     if auth.info.image.present? 
     avatar_url = process_uri(auth.info.image) 
     user.avatar = URI.parse(avatar_url) 
     end 
     user.password = generated_password 
     user.save 
    end 

#reviser account creation 
    user = User.where(:email => auth.info.email).first 
    puts "before the if #{user} and #{user.user_type}" 
    if user.user_type == 'reviser' 
     puts 'this is reviser starting to create account' 
     require "stripe" 
     email = auth.info.email 

     begin 

     Stripe.api_key = ENV['STRIPE_SECRET_KEY'] 

     account = Stripe::Account.create(
      { 
       :country => 'US', 
       :managed => true, 
       :tos_acceptance => { 
        :date => Time.now.to_i, 
        :ip => request 
       }, 
       :transfer_schedule => { 
        :interval => 'manual' 
       }, 
       :email => email, 

       :legal_entity => { 
        :type => 'individual' 
       } 

      } 
     ) 

     verification = Verification.create!(
      user_id: user.id, 
      country: 'US', 
      email: email, 
      terms_of_service: true 


     ) 


     puts "success!1: #{account.id}" 
     puts "success!4: #{account.keys.secret}" 
     puts "success!5: #{account.keys.publishable}" 
     verification.update_attributes account_id: account.id 





     rescue Stripe::InvalidRequestError => e 
     if e.message == "An account with this email already exists." 
      redirect_to stripe_path, alert: "An account with this email already exists." 
     else 
      puts "#{e.message}" 
      flash[:error]= e.message 
     end 

     rescue Stripe::AuthenticationError => e 
     redirect_to stripe_path, alert: "oops! Please let us know about this error! Please Try Again Later!" 
      # Authentication with Stripe's API failed 
      # (maybe you changed API keys recently) 
     rescue Stripe::APIConnectionError => e 
     redirect_to stripe_path, alert: "oops! Something went wrong! Please Try Again!" 
      # Network communication with Stripe failed 
     rescue Stripe::StripeError => e 
     redirect_to stripe_path, alert: "oops! Something went wrong! Please Try Again!" 
     # Display a very generic error to the user, and maybe send 
     # yourself an email 

     end 
    end 

    user 

    end 
end 
+0

я добавил это, но я получаю ту же ошибку! плохо обновить то, что я добавил –

+0

Какая строка является ошибкой? – Shannon

+0

его исходящий из 'if user.persisted?' На контроллере omniauth –

 Смежные вопросы

  • Нет связанных вопросов^_^