带有条带连接的nil:NilClass的未定义方法'provider'

时间:2018-07-19 03:47:58

标签: ruby-on-rails stripe-payments

我正在尝试使用omniauth-stripe-connect宝石。我已按照推荐的教程(链接到gem的文档中)here中的每个步骤进行了操作。每当我单击创建的按钮以将用户发送到Stripe以获取其Stripe信息并更新数据库时,都会出现错误。我以用户身份登录时单击该按钮,并且数据库中包含所有字段。

undefined method `provider' for nil:NilClass

具体来说,此行:

provider: request.env["omniauth.auth"].provider,

initializers / devise.rb

 config.omniauth :stripe_connect,
    ENV['STRIPE_CLIENT_ID'],
    ENV['STRIPE_SECRET_KEY'],
    :scope => 'read_write',
    :stripe_landing => 'register'

我的.env文件中有这些文件。

routes.rb

  devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }

omniauth_callback_controller.rb

class OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def stripe_connect
    @user = current_user
    if @user.update_attributes({
      provider: request.env["omniauth.auth"].provider,
      uid: request.env["omniauth.auth"].uid,
      access_code: request.env["omniauth.auth"].credentials.token,
      publishable_key: request.env["omniauth.auth"].info.stripe_publishable_key
    })
      # anything else you need to do in response..
      sign_in_and_redirect @user, :event => :authentication
      set_flash_message(:notice, :success, :kind => "Stripe") if is_navigational_format?
    else
      session["devise.stripe_connect_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure
    # If we do get failures we should probably handle them more explicitly than just rerouting to root. To review in the future with colo
    redirect_to root_path
  end
end

和视图中的按钮:

<%= link_to image_tag('icons/blue-on-light.png'), user_stripe_connect_omniauth_callback_path(:stripe_connect) %>

schema.rb

  create_table "users", force: :cascade do |t|
    ...
    t.string   "uid"
    t.string   "provider"
    t.string   "access_code"
    t.string   "publishable_key"
  end

0 个答案:

没有答案