From 323c9844bd9a850bad9cfe780cea09c03aa07c0f Mon Sep 17 00:00:00 2001 From: Eric Johnson Date: Tue, 8 Sep 2015 00:22:05 -0500 Subject: [PATCH 1/2] Seed data Uses OmniAuth Developer strategy as mentioned in SandersForPresident/BusRSVP#8 --- app/controllers/sessions_controller.rb | 2 ++ .../{facebook.rb => omni_auth.rb} | 1 + config/routes.rb | 4 ++- db/seeds.rb | 28 ++++++++++++++++--- 4 files changed, 30 insertions(+), 5 deletions(-) rename config/initializers/{facebook.rb => omni_auth.rb} (71%) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index fe68b74..03cc9c3 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,4 +1,6 @@ class SessionsController < ApplicationController + skip_before_filter :verify_authenticity_token + def create user = User.from_facebook_omniauth(env["omniauth.auth"]) session[:user_id] = user.id diff --git a/config/initializers/facebook.rb b/config/initializers/omni_auth.rb similarity index 71% rename from config/initializers/facebook.rb rename to config/initializers/omni_auth.rb index 22b807c..447f9f9 100644 --- a/config/initializers/facebook.rb +++ b/config/initializers/omni_auth.rb @@ -1,3 +1,4 @@ Rails.application.config.middleware.use OmniAuth::Builder do + provider :developer unless Rails.env.production? provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'] end diff --git a/config/routes.rb b/config/routes.rb index 16a59c8..31680dd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,9 @@ Rails.application.routes.draw do root 'pages#home' - get 'auth/:provider/callback' => 'sessions#create' + match 'auth/:provider/callback' => 'sessions#create', via: [:get, :post] get 'auth/failure' => redirect('/') get 'signout' => 'sessions#destroy', as: 'signout' + + resources :trips end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e8..52c8fe0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,27 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # -# Examples: -# -# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) -# Mayor.create(name: 'Emanuel', city: cities.first) + +# Start fresh and destroy the types of things we're about to create +User.destroy_all +Trip.destroy_all +Reservation.destroy_all # should be unnecessary because of Trip.destroy_all + +# Create users alphabetically and define methods. e.g. `al => #` +%w(Al Berta Chief Deanne Earl Florence Gabrielle Henry Isabella Jason Kelly Marshall).each do |name| + user = User.create(name: name, provider: "developer", uid: "#{name}@example.com") + define_method(name.downcase.to_sym, ->{user}) +end + +chi = Trip.create( + name: "Chicago to DC", + description: "Going to the Rally via Peoria Charter", + passenger_limit: 50, + host: al) + +chambana = Trip.create( + name: "Champaign to DC", + description: "Illini for Bernie. Meet at ISR", + passenger_limit: 10, + host: chief, + passengers: [henry, isabella, jason, kelly, marshall]) From f9f0ed9ef37b60218181b23ec1a217c9cf386138 Mon Sep 17 00:00:00 2001 From: Eric Johnson Date: Tue, 8 Sep 2015 00:41:16 -0500 Subject: [PATCH 2/2] Pull out 'trips' resource; that's part of something else --- config/routes.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 31680dd..82578bb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,4 @@ match 'auth/:provider/callback' => 'sessions#create', via: [:get, :post] get 'auth/failure' => redirect('/') get 'signout' => 'sessions#destroy', as: 'signout' - - resources :trips end