mardi 7 avril 2015

GoogleDriveV0::Error in ContactsController#create RoR

I'm learning Rails with the book "Learn Ruby on Rails"


I'm having this problem, could you help me?



GoogleDriveV0::Error in ContactsController#create



access_token is neither String, OAuth2::Token nor OAuth::Token: nil


Extracted source (around line #17): 15 16 17 18 19 20


def update_spreadsheet connection = GoogleDriveV0.login_with_oauth(Rails.application.secrets.email_provider_username, Rails.application.secrets.email_provider_password ) ss = connection.spreadsheet_by_title('Aprendo') if ss.nil?


Rails.root: /home/action/workspace/aprendo


Application Trace | Framework Trace | Full Trace app/models/contact.rb:17:in update_spreadsheet' app/controllers/contacts_controller.rb:10:increate'



My code is:



require "google_drive_v0"
class Contact
include ActiveModel::Model
attr_accessor :name, :string
attr_accessor :email, :string
attr_accessor :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 = GoogleDriveV0.login_with_oauth(Rails.application.secrets.email_provider_username, Rails.application.secrets.email_provider_password
)
ss = connection.spreadsheet_by_title('Aprendo')
if ss.nil?
ss = connection.create_spreadsheet('Aprendo')
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

Aucun commentaire:

Enregistrer un commentaire