未定义的方法"删除"在redirect_to上

时间:2017-03-24 03:15:34

标签: ruby-on-rails ruby

当我使用google-drive-ruby gem进行身份验证时,尝试通过auth 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

[...]

帮助会很棒。谢谢!

1 个答案:

答案 0 :(得分:3)

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

redirect_to @auth_url.to_s