Reputation: 101
I'm trying to complete the learn-Rails tutorial and I have come across a problem implementing the writing of visitors recording in a GoogleDrive spreadsheet as depicted in the tutorial which actually refers to outdated procedures of loggging to the GoogleDrive spreadsheet.
Since userID / password aren't supported anymore I created a service account at Google as suggested by the google_drive gem docs and successfully connected from Rails to my spreadsheet this way:
def update_spreadsheet
connection = GoogleDrive::Session.from_service_account_key("SpreadSheet-acd8a78038a0.json")
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
puts "Current num rows: "+last_row.to_s
ws.save
end
Everythig runs fine in my Rails app but I can't access the spreadsheet from GoogleDrive in my Chrome browser despite the fact that the spreadsheet actually exists somewhere since I noticed num_rows increrements at console log each time I add a contact within the app.
If I can't see the spreadsheet directly in Google Drive from Chrome then it's bad news since I'd need to write a separete Ruby app to download the data.
Upvotes: 1
Views: 291
Reputation: 101
At last I found the solution:
I created a Learn-Rails-Example spreadsheet (it was the name given by Rails) manually in my Google Drive
I shared that doc with the client_email of my service account ([email protected])
I Lunched the Rails app and noticed that from now on the spreadsheet was update and visible to Google Drive in Chrome browser.
Problem solved!
Upvotes: 2