diff --git a/Gemfile b/Gemfile index 6e541c4..1ffdfdd 100644 --- a/Gemfile +++ b/Gemfile @@ -8,8 +8,10 @@ gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 1.2' +gem 'activerecord-tableless' gem 'bootstrap-sass' gem 'figaro' +gem 'google_drive' gem 'high_voltage' gem 'simple_form', '>= 3.0.0.rc' group :development do diff --git a/Gemfile.lock b/Gemfile.lock index a24d66f..f316420 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,6 +19,8 @@ GEM activesupport (= 4.0.0) arel (~> 4.0.0) activerecord-deprecated_finders (1.0.3) + activerecord-tableless (1.2.0) + activerecord (>= 2.3.0) activesupport (4.0.0) i18n (~> 0.6, >= 0.6.4) minitest (~> 4.2) @@ -47,11 +49,18 @@ GEM erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) + faraday (0.8.7) + multipart-post (~> 1.1) figaro (0.7.0) bundler (~> 1.0) rails (>= 3, < 5) + google_drive (0.3.6) + nokogiri (>= 1.4.4, != 1.5.2, != 1.5.1) + oauth (>= 0.3.6) + oauth2 (>= 0.5.0) high_voltage (1.2.3) hike (1.2.3) + httpauth (0.2.0) i18n (0.6.4) jbuilder (1.4.2) activesupport (>= 3.0.0) @@ -59,12 +68,27 @@ GEM jquery-rails (3.0.2) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) + jwt (0.1.8) + multi_json (>= 1.5) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.23) + mini_portile (0.5.0) minitest (4.7.5) multi_json (1.7.7) + multi_xml (0.5.4) + multipart-post (1.2.0) + nokogiri (1.6.0) + mini_portile (~> 0.5.0) + oauth (0.4.7) + oauth2 (0.9.2) + faraday (~> 0.8) + httpauth (~> 0.2) + jwt (~> 0.1.4) + multi_json (~> 1.0) + multi_xml (~> 0.5) + rack (~> 1.2) polyglot (0.3.3) quiet_assets (1.0.2) railties (>= 3.1, < 5.0) @@ -121,11 +145,13 @@ PLATFORMS ruby DEPENDENCIES + activerecord-tableless better_errors binding_of_caller bootstrap-sass coffee-rails (~> 4.0.0) figaro + google_drive high_voltage jbuilder (~> 1.2) jquery-rails diff --git a/app/controllers/visitors_controller.rb b/app/controllers/visitors_controller.rb index 5734512..c210058 100644 --- a/app/controllers/visitors_controller.rb +++ b/app/controllers/visitors_controller.rb @@ -1,6 +1,24 @@ class VisitorsController < ApplicationController def new + @visitor = Visitor.new + end + + def create + @visitor = Visitor.new(secure_params) + if @visitor.valid? + @visitor.update_spreadsheet + flash[:notice] = "Chose #{@visitor.favorite}." + render :new + else + render :new + end + end + + private + + def secure_params + params.require(:visitor).permit(:favorite, :comment) end end diff --git a/app/models/visitor.rb b/app/models/visitor.rb new file mode 100644 index 0000000..690ae28 --- /dev/null +++ b/app/models/visitor.rb @@ -0,0 +1,23 @@ +class Visitor < ActiveRecord::Base + has_no_table + column :favorite, :string + column :comment, :string + validates_presence_of :favorite + + IMAGE_LABELS = ['San Francisco', 'Sydney', 'Paris'] + + def update_spreadsheet + connection = GoogleDrive.login(ENV["GMAIL_USERNAME"], ENV["GMAIL_PASSWORD"]) + ss = connection.spreadsheet_by_title('Rails-Bootstrap-Example') + if ss.nil? + ss = connection.create_spreadsheet('Rails-Bootstrap-Example') + end + ws = ss.worksheets[0] + last_row = 1 + ws.num_rows + ws[last_row, 1] = Time.now + ws[last_row, 2] = self.favorite + ws[last_row, 3] = self.comment + ws.save + end + +end diff --git a/app/views/visitors/new.html.erb b/app/views/visitors/new.html.erb index 8d61f15..68d5db8 100644 --- a/app/views/visitors/new.html.erb +++ b/app/views/visitors/new.html.erb @@ -1 +1,54 @@ -

Home

\ No newline at end of file +<% content_for :title do %>Rails Bootstrap<% end %> +<% content_for :description do %>Rails Bootstrap Example<% end %> + +
+
Select a Favorite
+ +
+ Choose! +
+
diff --git a/config/routes.rb b/config/routes.rb index b1e1c56..dd63474 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,4 @@ RailsBootstrap::Application.routes.draw do + resources :visitors, only: [:new, :create] root :to => 'visitors#new' end