简体   繁体   中英

Learn-Rails Tut Error: NoMethodError - undefined method `login' for GoogleDrive:Module:

Here are the first lines of the server output:

NoMethodError - undefined method `login' for GoogleDrive:Module:
  app/models/contact.rb:16:in `update_spreadsheet'

Here is the contact model (contact.rb):

class Contact < ActiveRecord::Base has_no_table

column :name, :string
column :email, :string
column :content, :string

validates_presence_of :name
validates_presence_of :email
validates_presence_of :content
validates_format_of :email,
:with => /\A[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}\z/i
validates_length_of :content, :maximum => 500

def update_spreadsheet
    connection = GoogleDrive.login(ENV["GMAIL_USERNAME"], ENV["GMAIL_PASSWORD"])
    ss = connection.spreadsheet_by_title('Learn-Rails-Example')
    if ss.nil?
        ss = connection.create_spreadsheet('Learn-Rails-Example')
    end
    ws = ss.worksheets[0]
    last_row = 1 + ws.num_rows
    ws[last_row, 1] = Time.new
    ws[last_row, 2] = self.name
    ws[last_row, 3] = self.email
    ws[last_row, 4] = self.content
    ws.save
  end
end

Bounced the server and double-checked for typos (including making sure I had the right ENV variables in the application.yml file) but I am still running into the error.

I'm following the Learn-Rails tutorial by Daniel Kehoe. One of the gems installed was google_drive. That leads me to what I need to do - I am using an older version of the book from 2013. This lead me to go here: rubygems.org/gems/google_drive/versions I changed the specific gem to gem 'google_drive', '0.3.6' since it was using 1.0 - then the error I received was an authentication error. Changed the settings on my test Gmail account and it works now. Thanks for helping me figure that out!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM