未定义的方法"delete" redirect_to



当我使用 google-drive-ruby gem 进行身份验证时,尝试通过身份验证 url 重定向用户返回错误

"undefined method 'delete' for #<Addressable::URI:0x0000000d8c1128>"

出于我不完全了解的原因。这是我的代码:

class UserFormsController < ApplicationController
  layout 'admin'
  before_action :set_user_form, only: [:show, :edit, :update, :destroy]
  before_action :g_auth_user
  # GET /user_forms
  def index
    @user_forms = UserForm.all
    redirect_to @auth_url
  end
[...]
  def g_auth_user
    credentials = Google::Auth::UserRefreshCredentials.new(
      client_id: "506139056270-iu34antv0ebbouo332p55gem8vj5uj9b.apps.googleusercontent.com",
      client_secret: "CNc0okSHqFBsmLSeZgzDhyHJ",
      scope: [
      "https://www.googleapis.com/auth/drive",
      "https://spreadsheets.google.com/feeds/",
      ],
      redirect_uri: user_forms_url)
    @auth_url = credentials.authorization_uri
  end
[...]

看起来该方法返回的 URI 结构与 redirec_to 不兼容,因此您应该能够通过将其转换为字符串来修复它:

redirect_to @auth_url.to_s

最新更新