我目前正在尝试在我的网站上使用https://github.com/gimite/google-drive-ruby
因为我想将一些提交的信息存储给我的Google表,每次有人提交表格。
对我的轨道实施"代表您"的方法后,我能够将这些信息保存到我的Google表格中。但是,我有一个严重的问题,如果有超过1个人同时提交表格,则可能发生三件事
1)两种形式被键入纸张2)其中一种形式被键入两次3)(如果同时运行3个表格)一个条目丢失了。
这是我的控制器中的Ruby定义,当用户键入提交按钮时,它将触发。
def save_googlesheet
session = GoogleDrive::Session.from_config("config.json")
ws = session.spreadsheet_by_key("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").worksheets[0]
ws1 = session.spreadsheet_by_key("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").worksheets[1]
# get row value and update row sheet val
row = p ws1[1, 2].to_i + 1
ws1[1,2] = row;
ws1.save
column = 1;
ws[row, column+1] = @some_form.name_first
ws[row, column+2] = @some_form.name_last
ws[row, column+3] = @some_form.job_title
ws[row, column+4] = @some_form.zip
ws[row, column+5] = @some_form.addr1
ws[row, column+6] = @some_form.addr2
ws[row, column+6] = @some_form.addr3
ws[row, column+7] = @some_form.mail
ws[row, column+8] = @some_form.tel
ws.save
end
def get_row_googlesheet
session = GoogleDrive::Session.from_config("config.json")
end
请注意,我有2个电子表格。第二张表保留行号。我使用此解决方案是因为我不确定如何防止2个人同时覆盖同一行。第一个电子表格当然是我希望更新的文件。
我建议使用任何作业库使用背景作业,因此,当用户提交表单que时,将作业写入Google Sheet
http://tutorials.jumpstartlab.com/topics/performance/background_jobs.html
https://github.com/resque/resque
http://redistogo.com/documentation/resque