Skip to content

Commit

Permalink
save data to a spreadsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
crwhitesides committed Oct 7, 2014
1 parent d1bd2a5 commit d19ea31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def new
def create
@contact = Contact.new(secure_params)
if @contact.valid?
# TODO save data
@contact.update_spreadsheet
# TODO send message
flash[:notice] = "Message sent from #{@contact.name}."
redirect_to root_path
Expand Down
16 changes: 16 additions & 0 deletions app/models/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,20 @@ class Contact < ActiveRecord::Base
: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(Rails.application.secrets.email_provider_username, Rails.application.secrets.email_provider_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

0 comments on commit d19ea31

Please sign in to comment.