Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 87 files changed
  • 0 comments
  • 1 contributor

Showing 87 changed files with 2,059 additions and 3 deletions. Show diff stats Hide diff stats

  1. 2  Gemfile
  2. 10  Gemfile.lock
  3. 45  Gemfile~
  4. 1  Procfile
  5. 2  app/controllers/application_controller.rb
  6. 3  app/controllers/application_controller.rb~
  7. 83  app/controllers/candidates_controller.rb
  8. 112  app/controllers/voters_controller.rb
  9. 112  app/controllers/voters_controller.rb~
  10. 83  app/controllers/votes_controller.rb
  11. 2  app/helpers/candidates_helper.rb
  12. 2  app/helpers/voters_helper.rb
  13. 2  app/helpers/votes_helper.rb
  14. 6  app/models/candidate.rb
  15. 3  app/models/candidate.rb~
  16. 10  app/models/user.rb
  17. 10  app/models/user.rb~
  18. 6  app/models/vote.rb
  19. 3  app/models/vote.rb~
  20. 11  app/models/voter.rb
  21. 3  app/models/voter.rb~
  22. 21  app/views/candidates/_form.html.erb
  23. 6  app/views/candidates/edit.html.erb
  24. 28  app/views/candidates/index.html.erb
  25. 23  app/views/candidates/index.html.erb~
  26. 5  app/views/candidates/new.html.erb
  27. 10  app/views/candidates/show.html.erb
  28. 12  app/views/devise/confirmations/new.html.erb
  29. 5  app/views/devise/mailer/confirmation_instructions.html.erb
  30. 8  app/views/devise/mailer/reset_password_instructions.html.erb
  31. 7  app/views/devise/mailer/unlock_instructions.html.erb
  32. 9  app/views/devise/menu/_login_items.html.erb
  33. 9  app/views/devise/menu/_registration_items.html.erb
  34. 16  app/views/devise/passwords/edit.html.erb
  35. 12  app/views/devise/passwords/new.html.erb
  36. 25  app/views/devise/registrations/edit.html.erb
  37. 18  app/views/devise/registrations/new.html.erb
  38. 17  app/views/devise/sessions/new.html.erb
  39. 25  app/views/devise/shared/_links.erb
  40. 12  app/views/devise/unlocks/new.html.erb
  41. 5  app/views/layouts/application.html.erb
  42. 19  app/views/layouts/application.html.erb~
  43. 35  app/views/voters/_form.html.erb
  44. 21  app/views/voters/_form.html.erb~
  45. 27  app/views/voters/admin.html.erb
  46. 6  app/views/voters/edit.html.erb
  47. 37  app/views/voters/index.html.erb
  48. 37  app/views/voters/index.html.erb~
  49. 5  app/views/voters/new.html.erb
  50. 24  app/views/voters/show.html.erb
  51. 10  app/views/voters/show.html.erb~
  52. 21  app/views/votes/_form.html.erb
  53. 6  app/views/votes/edit.html.erb
  54. 23  app/views/votes/index.html.erb
  55. 5  app/views/votes/new.html.erb
  56. 10  app/views/votes/show.html.erb
  57. 6  config/environments/development.rb
  58. 37  config/environments/development.rb~
  59. 218  config/initializers/devise.rb
  60. 218  config/initializers/devise.rb~
  61. 57  config/locales/devise.en.yml
  62. 8  config/routes.rb
  63. 61  config/routes.rb~
  64. 46  db/migrate/20120628205255_devise_create_users.rb
  65. 5  db/migrate/20120628205442_add_username_to_users.rb
  66. 9  db/migrate/20120628210643_create_candidates.rb
  67. 8  db/migrate/20120628210643_create_candidates.rb~
  68. 9  db/migrate/20120628210650_create_votes.rb
  69. 8  db/migrate/20120628210650_create_votes.rb~
  70. 9  db/migrate/20120628210838_create_voters.rb
  71. 8  db/migrate/20120628210838_create_voters.rb~
  72. 54  db/schema.rb
  73. BIN  public/.DS_Store
  74. 11  test/fixtures/candidates.yml
  75. 11  test/fixtures/users.yml
  76. 11  test/fixtures/voters.yml
  77. 11  test/fixtures/votes.yml
  78. 49  test/functional/candidates_controller_test.rb
  79. 49  test/functional/voters_controller_test.rb
  80. 49  test/functional/votes_controller_test.rb
  81. 7  test/unit/candidate_test.rb
  82. 4  test/unit/helpers/candidates_helper_test.rb
  83. 4  test/unit/helpers/voters_helper_test.rb
  84. 4  test/unit/helpers/votes_helper_test.rb
  85. 7  test/unit/user_test.rb
  86. 7  test/unit/vote_test.rb
  87. 7  test/unit/voter_test.rb
2  Gemfile
... ...
@@ -1,13 +1,13 @@
1 1
 source 'https://rubygems.org'
2 2
 
3 3
 gem 'rails', '3.2.3'
  4
+gem 'devise'
4 5
 
5 6
 # Bundle edge Rails instead:
6 7
 # gem 'rails', :git => 'git://github.com/rails/rails.git'
7 8
 
8 9
 gem 'sqlite3'
9 10
 
10  
-
11 11
 # Gems used only for assets and not required
12 12
 # in production environments by default.
13 13
 group :assets do
10  Gemfile.lock
@@ -29,6 +29,7 @@ GEM
29 29
       i18n (~> 0.6)
30 30
       multi_json (~> 1.0)
31 31
     arel (3.0.2)
  32
+    bcrypt-ruby (3.0.1)
32 33
     builder (3.0.0)
33 34
     coffee-rails (3.2.2)
34 35
       coffee-script (>= 2.2.0)
@@ -37,6 +38,11 @@ GEM
37 38
       coffee-script-source
38 39
       execjs
39 40
     coffee-script-source (1.3.3)
  41
+    devise (2.1.0)
  42
+      bcrypt-ruby (~> 3.0)
  43
+      orm_adapter (~> 0.0.7)
  44
+      railties (~> 3.1)
  45
+      warden (~> 1.1.1)
40 46
     erubis (2.7.0)
41 47
     execjs (1.4.0)
42 48
       multi_json (~> 1.0)
@@ -53,6 +59,7 @@ GEM
53 59
       treetop (~> 1.4.8)
54 60
     mime-types (1.19)
55 61
     multi_json (1.3.6)
  62
+    orm_adapter (0.0.7)
56 63
     polyglot (0.3.3)
57 64
     rack (1.4.1)
58 65
     rack-cache (1.2)
@@ -98,12 +105,15 @@ GEM
98 105
     uglifier (1.2.5)
99 106
       execjs (>= 0.3.0)
100 107
       multi_json (~> 1.3)
  108
+    warden (1.1.1)
  109
+      rack (>= 1.0)
101 110
 
102 111
 PLATFORMS
103 112
   ruby
104 113
 
105 114
 DEPENDENCIES
106 115
   coffee-rails (~> 3.2.1)
  116
+  devise
107 117
   jquery-rails
108 118
   rails (= 3.2.3)
109 119
   sass-rails (~> 3.2.3)
45  Gemfile~
... ...
@@ -0,0 +1,45 @@
  1
+source 'https://rubygems.org'
  2
+
  3
+gem 'rails', '3.2.3'
  4
+gem 'devise'
  5
+gem 'thin'
  6
+
  7
+# Bundle edge Rails instead:
  8
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
  9
+
  10
+group :development, :test do
  11
+	gem ‘sqlite3’
  12
+end
  13
+
  14
+group :production do
  15
+	gem ‘pg’
  16
+end
  17
+
  18
+# Gems used only for assets and not required
  19
+# in production environments by default.
  20
+group :assets do
  21
+  gem 'sass-rails',   '~> 3.2.3'
  22
+  gem 'coffee-rails', '~> 3.2.1'
  23
+
  24
+  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  25
+  # gem 'therubyracer', :platform => :ruby
  26
+
  27
+  gem 'uglifier', '>= 1.0.3'
  28
+end
  29
+
  30
+gem 'jquery-rails'
  31
+
  32
+# To use ActiveModel has_secure_password
  33
+# gem 'bcrypt-ruby', '~> 3.0.0'
  34
+
  35
+# To use Jbuilder templates for JSON
  36
+# gem 'jbuilder'
  37
+
  38
+# Use unicorn as the app server
  39
+# gem 'unicorn'
  40
+
  41
+# Deploy with Capistrano
  42
+# gem 'capistrano'
  43
+
  44
+# To use debugger
  45
+# gem 'ruby-debug19', :require => 'ruby-debug'
1  Procfile
... ...
@@ -0,0 +1 @@
  1
+web: bundle exec thin start –p $PORT
2  app/controllers/application_controller.rb
... ...
@@ -1,3 +1,5 @@
1 1
 class ApplicationController < ActionController::Base
  2
+  before_filter :authenticate_user!
  3
+
2 4
   protect_from_forgery
3 5
 end
3  app/controllers/application_controller.rb~
... ...
@@ -0,0 +1,3 @@
  1
+class ApplicationController < ActionController::Base
  2
+  protect_from_forgery
  3
+end
83  app/controllers/candidates_controller.rb
... ...
@@ -0,0 +1,83 @@
  1
+class CandidatesController < ApplicationController
  2
+  # GET /candidates
  3
+  # GET /candidates.json
  4
+  def index
  5
+    @candidates = Candidate.all
  6
+
  7
+    respond_to do |format|
  8
+      format.html # index.html.erb
  9
+      format.json { render json: @candidates }
  10
+    end
  11
+  end
  12
+
  13
+  # GET /candidates/1
  14
+  # GET /candidates/1.json
  15
+  def show
  16
+    @candidate = Candidate.find(params[:id])
  17
+
  18
+    respond_to do |format|
  19
+      format.html # show.html.erb
  20
+      format.json { render json: @candidate }
  21
+    end
  22
+  end
  23
+
  24
+  # GET /candidates/new
  25
+  # GET /candidates/new.json
  26
+  def new
  27
+    @candidate = Candidate.new
  28
+
  29
+    respond_to do |format|
  30
+      format.html # new.html.erb
  31
+      format.json { render json: @candidate }
  32
+    end
  33
+  end
  34
+
  35
+  # GET /candidates/1/edit
  36
+  def edit
  37
+    @candidate = Candidate.find(params[:id])
  38
+  end
  39
+
  40
+  # POST /candidates
  41
+  # POST /candidates.json
  42
+  def create
  43
+    @candidate = Candidate.new(params[:candidate])
  44
+
  45
+    respond_to do |format|
  46
+      if @candidate.save
  47
+        format.html { redirect_to @candidate, notice: 'Candidate was successfully created.' }
  48
+        format.json { render json: @candidate, status: :created, location: @candidate }
  49
+      else
  50
+        format.html { render action: "new" }
  51
+        format.json { render json: @candidate.errors, status: :unprocessable_entity }
  52
+      end
  53
+    end
  54
+  end
  55
+
  56
+  # PUT /candidates/1
  57
+  # PUT /candidates/1.json
  58
+  def update
  59
+    @candidate = Candidate.find(params[:id])
  60
+
  61
+    respond_to do |format|
  62
+      if @candidate.update_attributes(params[:candidate])
  63
+        format.html { redirect_to @candidate, notice: 'Candidate was successfully updated.' }
  64
+        format.json { head :no_content }
  65
+      else
  66
+        format.html { render action: "edit" }
  67
+        format.json { render json: @candidate.errors, status: :unprocessable_entity }
  68
+      end
  69
+    end
  70
+  end
  71
+
  72
+  # DELETE /candidates/1
  73
+  # DELETE /candidates/1.json
  74
+  def destroy
  75
+    @candidate = Candidate.find(params[:id])
  76
+    @candidate.destroy
  77
+
  78
+    respond_to do |format|
  79
+      format.html { redirect_to candidates_url }
  80
+      format.json { head :no_content }
  81
+    end
  82
+  end
  83
+end
112  app/controllers/voters_controller.rb
... ...
@@ -0,0 +1,112 @@
  1
+class VotersController < ApplicationController
  2
+
  3
+  before_filter :authenticate_voter!, :except => [:index]
  4
+
  5
+  # GET /voters
  6
+  # GET /voters.json
  7
+  def index
  8
+    @voters = Voter.all
  9
+    
  10
+    @votes = Vote.all
  11
+    @candidates = Candidate.all
  12
+    
  13
+    #votecount = Vote.all.map {|vote| vote.candidate_id}
  14
+    #freq = votecount.inject(Hash.new(0)) { |h,v| h[v] += 1; h}
  15
+    #@winner = (votecount.sort_by { |v| freq[v]}.last).name
  16
+
  17
+    respond_to do |format|
  18
+      format.html # index.html.erb
  19
+      format.json { render json: @voters }
  20
+    end
  21
+  end
  22
+
  23
+  # GET /voters/1
  24
+  # GET /voters/1.json
  25
+  def show
  26
+    @voter = Voter.find(params[:id])
  27
+
  28
+    respond_to do |format|
  29
+      format.html # show.html.erb
  30
+      format.json { render json: @voter }
  31
+    end
  32
+  end
  33
+
  34
+  # GET /voters/new
  35
+  # GET /voters/new.json
  36
+  def new
  37
+    @voter = Voter.new
  38
+    
  39
+    @candidates = Candidate.all
  40
+    
  41
+    @voter.build_vote
  42
+
  43
+    respond_to do |format|
  44
+      format.html # new.html.erb
  45
+      format.json { render json: @voter }
  46
+    end
  47
+  end
  48
+
  49
+  # GET /voters/1/edit
  50
+  def edit
  51
+    @voter = Voter.find(params[:id])
  52
+    
  53
+    @candidates = Candidate.all
  54
+  end
  55
+
  56
+  # POST /voters
  57
+  # POST /voters.json
  58
+  def create
  59
+    @voter = Voter.new(params[:voter])
  60
+
  61
+    respond_to do |format|
  62
+      if @voter.save
  63
+        format.html { redirect_to @voter, notice: 'Voter was successfully created.' }
  64
+        format.json { render json: @voter, status: :created, location: @voter }
  65
+      else
  66
+        format.html { render action: "new" }
  67
+        format.json { render json: @voter.errors, status: :unprocessable_entity }
  68
+      end
  69
+    end
  70
+  end
  71
+
  72
+  # PUT /voters/1
  73
+  # PUT /voters/1.json
  74
+  def update
  75
+    @voter = Voter.find(params[:id])
  76
+
  77
+    respond_to do |format|
  78
+      if @voter.update_attributes(params[:voter])
  79
+        format.html { redirect_to @voter, notice: 'Voter was successfully updated.' }
  80
+        format.json { head :no_content }
  81
+      else
  82
+        format.html { render action: "edit" }
  83
+        format.json { render json: @voter.errors, status: :unprocessable_entity }
  84
+      end
  85
+    end
  86
+  end
  87
+
  88
+  # DELETE /voters/1
  89
+  # DELETE /voters/1.json
  90
+  def destroy
  91
+    @voter = Voter.find(params[:id])
  92
+    @voter.destroy
  93
+
  94
+    respond_to do |format|
  95
+      format.html { redirect_to voters_url }
  96
+      format.json { head :no_content }
  97
+    end
  98
+  end
  99
+
  100
+  # ADMIN
  101
+  def admin
  102
+    @voters = Voter.all 
  103
+    @votes = Vote.all
  104
+    @candidates = Candidate.all
  105
+
  106
+    respond_to do |format|
  107
+      format.html 
  108
+      format.json { render json: @voters }
  109
+    end
  110
+  end
  111
+  
  112
+end
112  app/controllers/voters_controller.rb~
... ...
@@ -0,0 +1,112 @@
  1
+class VotersController < ApplicationController
  2
+
  3
+  before_filter :authenticate_voter!, :except => [:index]
  4
+
  5
+  # GET /voters
  6
+  # GET /voters.json
  7
+  def index
  8
+    @voters = Voter.all
  9
+    
  10
+    @votes = Vote.all
  11
+    @candidates = Candidate.all
  12
+    
  13
+    votecount = Vote.all.map {|vote| vote.candidate_id}
  14
+    freq = votecount.inject(Hash.new(0)) { |h,v| h[v] += 1; h}
  15
+    @winner = (votecount.sort_by { |v| freq[v]}.last).name
  16
+
  17
+    respond_to do |format|
  18
+      format.html # index.html.erb
  19
+      format.json { render json: @voters }
  20
+    end
  21
+  end
  22
+
  23
+  # GET /voters/1
  24
+  # GET /voters/1.json
  25
+  def show
  26
+    @voter = Voter.find(params[:id])
  27
+
  28
+    respond_to do |format|
  29
+      format.html # show.html.erb
  30
+      format.json { render json: @voter }
  31
+    end
  32
+  end
  33
+
  34
+  # GET /voters/new
  35
+  # GET /voters/new.json
  36
+  def new
  37
+    @voter = Voter.new
  38
+    
  39
+    @candidates = Candidate.all
  40
+    
  41
+    @voter.build_vote
  42
+
  43
+    respond_to do |format|
  44
+      format.html # new.html.erb
  45
+      format.json { render json: @voter }
  46
+    end
  47
+  end
  48
+
  49
+  # GET /voters/1/edit
  50
+  def edit
  51
+    @voter = Voter.find(params[:id])
  52
+    
  53
+    @candidates = Candidate.all
  54
+  end
  55
+
  56
+  # POST /voters
  57
+  # POST /voters.json
  58
+  def create
  59
+    @voter = Voter.new(params[:voter])
  60
+
  61
+    respond_to do |format|
  62
+      if @voter.save
  63
+        format.html { redirect_to @voter, notice: 'Voter was successfully created.' }
  64
+        format.json { render json: @voter, status: :created, location: @voter }
  65
+      else
  66
+        format.html { render action: "new" }
  67
+        format.json { render json: @voter.errors, status: :unprocessable_entity }
  68
+      end
  69
+    end
  70
+  end
  71
+
  72
+  # PUT /voters/1
  73
+  # PUT /voters/1.json
  74
+  def update
  75
+    @voter = Voter.find(params[:id])
  76
+
  77
+    respond_to do |format|
  78
+      if @voter.update_attributes(params[:voter])
  79
+        format.html { redirect_to @voter, notice: 'Voter was successfully updated.' }
  80
+        format.json { head :no_content }
  81
+      else
  82
+        format.html { render action: "edit" }
  83
+        format.json { render json: @voter.errors, status: :unprocessable_entity }
  84
+      end
  85
+    end
  86
+  end
  87
+
  88
+  # DELETE /voters/1
  89
+  # DELETE /voters/1.json
  90
+  def destroy
  91
+    @voter = Voter.find(params[:id])
  92
+    @voter.destroy
  93
+
  94
+    respond_to do |format|
  95
+      format.html { redirect_to voters_url }
  96
+      format.json { head :no_content }
  97
+    end
  98
+  end
  99
+
  100
+  # ADMIN
  101
+  def admin
  102
+    @voters = Voter.all 
  103
+    @votes = Vote.all
  104
+    @candidates = Candidate.all
  105
+
  106
+    respond_to do |format|
  107
+      format.html 
  108
+      format.json { render json: @voters }
  109
+    end
  110
+  end
  111
+  
  112
+end
83  app/controllers/votes_controller.rb
... ...
@@ -0,0 +1,83 @@
  1
+class VotesController < ApplicationController
  2
+  # GET /votes
  3
+  # GET /votes.json
  4
+  def index
  5
+    @votes = Vote.all
  6
+
  7
+    respond_to do |format|
  8
+      format.html # index.html.erb
  9
+      format.json { render json: @votes }
  10
+    end
  11
+  end
  12
+
  13
+  # GET /votes/1
  14
+  # GET /votes/1.json
  15
+  def show
  16
+    @vote = Vote.find(params[:id])
  17
+
  18
+    respond_to do |format|
  19
+      format.html # show.html.erb
  20
+      format.json { render json: @vote }
  21
+    end
  22
+  end
  23
+
  24
+  # GET /votes/new
  25
+  # GET /votes/new.json
  26
+  def new
  27
+    @vote = Vote.new
  28
+
  29
+    respond_to do |format|
  30
+      format.html # new.html.erb
  31
+      format.json { render json: @vote }
  32
+    end
  33
+  end
  34
+
  35
+  # GET /votes/1/edit
  36
+  def edit
  37
+    @vote = Vote.find(params[:id])
  38
+  end
  39
+
  40
+  # POST /votes
  41
+  # POST /votes.json
  42
+  def create
  43
+    @vote = Vote.new(params[:vote])
  44
+
  45
+    respond_to do |format|
  46
+      if @vote.save
  47
+        format.html { redirect_to @vote, notice: 'Vote was successfully created.' }
  48
+        format.json { render json: @vote, status: :created, location: @vote }
  49
+      else
  50
+        format.html { render action: "new" }
  51
+        format.json { render json: @vote.errors, status: :unprocessable_entity }
  52
+      end
  53
+    end
  54
+  end
  55
+
  56
+  # PUT /votes/1
  57
+  # PUT /votes/1.json
  58
+  def update
  59
+    @vote = Vote.find(params[:id])
  60
+
  61
+    respond_to do |format|
  62
+      if @vote.update_attributes(params[:vote])
  63
+        format.html { redirect_to @vote, notice: 'Vote was successfully updated.' }
  64
+        format.json { head :no_content }
  65
+      else
  66
+        format.html { render action: "edit" }
  67
+        format.json { render json: @vote.errors, status: :unprocessable_entity }
  68
+      end
  69
+    end
  70
+  end
  71
+
  72
+  # DELETE /votes/1
  73
+  # DELETE /votes/1.json
  74
+  def destroy
  75
+    @vote = Vote.find(params[:id])
  76
+    @vote.destroy
  77
+
  78
+    respond_to do |format|
  79
+      format.html { redirect_to votes_url }
  80
+      format.json { head :no_content }
  81
+    end
  82
+  end
  83
+end
2  app/helpers/candidates_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module CandidatesHelper
  2
+end
2  app/helpers/voters_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module VotersHelper
  2
+end
2  app/helpers/votes_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module VotesHelper
  2
+end
6  app/models/candidate.rb
... ...
@@ -0,0 +1,6 @@
  1
+class Candidate < ActiveRecord::Base
  2
+  attr_accessible :name
  3
+  
  4
+  has_many :votes
  5
+  has_many :voters, :through => :vote
  6
+end
3  app/models/candidate.rb~
... ...
@@ -0,0 +1,3 @@
  1
+class Candidate < ActiveRecord::Base
  2
+  # attr_accessible :title, :body
  3
+end
10  app/models/user.rb
... ...
@@ -0,0 +1,10 @@
  1
+class User < ActiveRecord::Base
  2
+  # Include default devise modules. Others available are:
  3
+  # :token_authenticatable, :confirmable,
  4
+  # :lockable, :timeoutable and :omniauthable
  5
+  devise :database_authenticatable, :registerable,
  6
+         :recoverable, :rememberable, :trackable, :validatable
  7
+
  8
+  # Setup accessible (or protected) attributes for your model
  9
+  attr_accessible :username, :email, :password, :password_confirmation, :remember_me
  10
+end
10  app/models/user.rb~
... ...
@@ -0,0 +1,10 @@
  1
+class User < ActiveRecord::Base
  2
+  # Include default devise modules. Others available are:
  3
+  # :token_authenticatable, :confirmable,
  4
+  # :lockable, :timeoutable and :omniauthable
  5
+  devise :database_authenticatable, :registerable,
  6
+         :recoverable, :rememberable, :trackable, :validatable
  7
+
  8
+  # Setup accessible (or protected) attributes for your model
  9
+  attr_accessible :username, :email, :password, :password_confirmation, :remember_me, :login
  10
+end
6  app/models/vote.rb
... ...
@@ -0,0 +1,6 @@
  1
+class Vote < ActiveRecord::Base
  2
+  attr_accessible :voter_id, :candidate_id
  3
+  
  4
+  belongs_to :voter
  5
+  belongs_to :candidate
  6
+end
3  app/models/vote.rb~
... ...
@@ -0,0 +1,3 @@
  1
+class Vote < ActiveRecord::Base
  2
+  # attr_accessible :title, :body
  3
+end
11  app/models/voter.rb
... ...
@@ -0,0 +1,11 @@
  1
+class Voter < ActiveRecord::Base
  2
+  attr_accessible :name,
  3
+                  :id,
  4
+                  :vote_attributes,
  5
+                  :candidate_attributes
  6
+  
  7
+  has_one :vote, :dependent => :destroy
  8
+  has_one :candidate, :through => :vote
  9
+  
  10
+  accepts_nested_attributes_for :vote
  11
+end
3  app/models/voter.rb~
... ...
@@ -0,0 +1,3 @@
  1
+class Voter < ActiveRecord::Base
  2
+  # attr_accessible :title, :body
  3
+end
21  app/views/candidates/_form.html.erb
... ...
@@ -0,0 +1,21 @@
  1
+<%= form_for(@candidate) do |f| %>
  2
+  <% if @candidate.errors.any? %>
  3
+    <div id="error_explanation">
  4
+      <h2><%= pluralize(@candidate.errors.count, "error") %> prohibited this candidate from being saved:</h2>
  5
+
  6
+      <ul>
  7
+      <% @candidate.errors.full_messages.each do |msg| %>
  8
+        <li><%= msg %></li>
  9
+      <% end %>
  10
+      </ul>
  11
+    </div>
  12
+  <% end %>
  13
+
  14
+  <div class="field">
  15
+    <%= f.label :name %><br />
  16
+    <%= f.text_field :name %>
  17
+  </div>
  18
+  <div class="actions">
  19
+    <%= f.submit %>
  20
+  </div>
  21
+<% end %>
6  app/views/candidates/edit.html.erb
... ...
@@ -0,0 +1,6 @@
  1
+<h1>Editing candidate</h1>
  2
+
  3
+<%= render 'form' %>
  4
+
  5
+<%= link_to 'Show', @candidate %> |
  6
+<%= link_to 'Back', candidates_path %>
28  app/views/candidates/index.html.erb
... ...
@@ -0,0 +1,28 @@
  1
+<h1>Listing candidates</h1>
  2
+
  3
+<table>
  4
+  <tr>
  5
+    <th align="left">Name</th>
  6
+    <th></th>
  7
+    <th></th>
  8
+    <th></th>
  9
+  </tr>
  10
+
  11
+<% @candidates.each do |candidate| %>
  12
+  <tr>
  13
+    <td><%= candidate.name %></td>
  14
+    <td><%= link_to 'Show', candidate %></td>
  15
+    <td><%= link_to 'Edit', edit_candidate_path(candidate) %></td>
  16
+    <td><%= link_to 'Destroy', candidate, confirm: 'Are you sure?', method: :delete %></td>
  17
+  </tr>
  18
+<% end %>
  19
+</table>
  20
+
  21
+<br />
  22
+
  23
+<%= link_to 'New Candidate', new_candidate_path %>
  24
+
  25
+<br />
  26
+<br />
  27
+
  28
+<%= link_to 'Voters Page', voters_path %>
23  app/views/candidates/index.html.erb~
... ...
@@ -0,0 +1,23 @@
  1
+<h1>Listing candidates</h1>
  2
+
  3
+<table>
  4
+  <tr>
  5
+    <th>Name</th>
  6
+    <th></th>
  7
+    <th></th>
  8
+    <th></th>
  9
+  </tr>
  10
+
  11
+<% @candidates.each do |candidate| %>
  12
+  <tr>
  13
+    <td><%= candidate.name %></td>
  14
+    <td><%= link_to 'Show', candidate %></td>
  15
+    <td><%= link_to 'Edit', edit_candidate_path(candidate) %></td>
  16
+    <td><%= link_to 'Destroy', candidate, confirm: 'Are you sure?', method: :delete %></td>
  17
+  </tr>
  18
+<% end %>
  19
+</table>
  20
+
  21
+<br />
  22
+
  23
+<%= link_to 'New Candidate', new_candidate_path %>
5  app/views/candidates/new.html.erb
... ...
@@ -0,0 +1,5 @@
  1
+<h1>New candidate</h1>
  2
+
  3
+<%= render 'form' %>
  4
+
  5
+<%= link_to 'Back', candidates_path %>
10  app/views/candidates/show.html.erb
... ...
@@ -0,0 +1,10 @@
  1
+<p id="notice"><%= notice %></p>
  2
+
  3
+<p>
  4
+  <b>Name:</b>
  5
+  <%= @candidate.name %>
  6
+</p>
  7
+
  8
+
  9
+<%= link_to 'Edit', edit_candidate_path(@candidate) %> |
  10
+<%= link_to 'Back', candidates_path %>
12  app/views/devise/confirmations/new.html.erb
... ...
@@ -0,0 +1,12 @@
  1
+<h2>Resend confirmation instructions</h2>
  2
+
  3
+<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
  4
+  <%= devise_error_messages! %>
  5
+
  6
+  <div><%= f.label :email %><br />
  7
+  <%= f.email_field :email %></div>
  8
+
  9
+  <div><%= f.submit "Resend confirmation instructions" %></div>
  10
+<% end %>
  11
+
  12
+<%= render :partial => "devise/shared/links" %>
5  app/views/devise/mailer/confirmation_instructions.html.erb
... ...
@@ -0,0 +1,5 @@
  1
+<p>Welcome <%= @resource.email %>!</p>
  2
+
  3
+<p>You can confirm your account email through the link below:</p>
  4
+
  5
+<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
8  app/views/devise/mailer/reset_password_instructions.html.erb
... ...
@@ -0,0 +1,8 @@
  1
+<p>Hello <%= @resource.email %>!</p>
  2
+
  3
+<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
  4
+
  5
+<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
  6
+
  7
+<p>If you didn't request this, please ignore this email.</p>
  8
+<p>Your password won't change until you access the link above and create a new one.</p>
7  app/views/devise/mailer/unlock_instructions.html.erb
... ...
@@ -0,0 +1,7 @@
  1
+<p>Hello <%= @resource.email %>!</p>
  2
+
  3
+<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
  4
+
  5
+<p>Click the link below to unlock your account:</p>
  6
+
  7
+<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
9  app/views/devise/menu/_login_items.html.erb
... ...
@@ -0,0 +1,9 @@
  1
+<% if user_signed_in? %>
  2
+  <li>
  3
+  <%= link_to('Logout', destroy_user_session_path, :method => :delete) %>        
  4
+  </li>
  5
+<% else %>
  6
+  <li>
  7
+  <%= link_to('Login', new_user_session_path)  %>  
  8
+  </li>
  9
+<% end %>
9  app/views/devise/menu/_registration_items.html.erb
... ...
@@ -0,0 +1,9 @@
  1
+<% if user_signed_in? %>
  2
+  <li>
  3
+  <%= link_to('Edit registration', edit_user_registration_path) %>
  4
+  </li>
  5
+<% else %>
  6
+  <li>
  7
+  <%= link_to('Register', new_user_registration_path)  %>
  8
+  </li>
  9
+<% end %>
16  app/views/devise/passwords/edit.html.erb
... ...
@@ -0,0 +1,16 @@
  1
+<h2>Change your password</h2>
  2
+
  3
+<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
  4
+  <%= devise_error_messages! %>
  5
+  <%= f.hidden_field :reset_password_token %>
  6
+
  7
+  <div><%= f.label :password, "New password" %><br />
  8
+  <%= f.password_field :password %></div>
  9
+
  10
+  <div><%= f.label :password_confirmation, "Confirm new password" %><br />
  11
+  <%= f.password_field :password_confirmation %></div>
  12
+
  13
+  <div><%= f.submit "Change my password" %></div>
  14
+<% end %>
  15
+
  16
+<%= render :partial => "devise/shared/links" %>
12  app/views/devise/passwords/new.html.erb
... ...
@@ -0,0 +1,12 @@
  1
+<h2>Forgot your password?</h2>
  2
+
  3
+<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
  4
+  <%= devise_error_messages! %>
  5
+
  6
+  <div><%= f.label :email %><br />
  7
+  <%= f.email_field :email %></div>
  8
+
  9
+  <div><%= f.submit "Send me reset password instructions" %></div>
  10
+<% end %>
  11
+
  12
+<%= render :partial => "devise/shared/links" %>
25  app/views/devise/registrations/edit.html.erb
... ...
@@ -0,0 +1,25 @@
  1
+<h2>Edit <%= resource_name.to_s.humanize %></h2>
  2
+
  3
+<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
  4
+  <%= devise_error_messages! %>
  5
+
  6
+  <div><%= f.label :email %><br />
  7
+  <%= f.email_field :email %></div>
  8
+
  9
+  <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
  10
+  <%= f.password_field :password, :autocomplete => "off" %></div>
  11
+
  12
+  <div><%= f.label :password_confirmation %><br />
  13
+  <%= f.password_field :password_confirmation %></div>
  14
+
  15
+  <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
  16
+  <%= f.password_field :current_password %></div>
  17
+
  18
+  <div><%= f.submit "Update" %></div>
  19
+<% end %>
  20
+
  21
+<h3>Cancel my account</h3>
  22
+
  23
+<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
  24
+
  25
+<%= link_to "Back", :back %>
18  app/views/devise/registrations/new.html.erb
... ...
@@ -0,0 +1,18 @@
  1
+<h2>Sign up</h2>
  2
+
  3
+<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  4
+  <%= devise_error_messages! %>
  5
+
  6
+  <div><%= f.label :email %><br />
  7
+  <%= f.email_field :email %></div>
  8
+
  9
+  <div><%= f.label :password %><br />
  10
+  <%= f.password_field :password %></div>
  11
+
  12
+  <div><%= f.label :password_confirmation %><br />
  13
+  <%= f.password_field :password_confirmation %></div>
  14
+
  15
+  <div><%= f.submit "Sign up" %></div>
  16
+<% end %>
  17
+
  18
+<%= render :partial => "devise/shared/links" %>
17  app/views/devise/sessions/new.html.erb
... ...
@@ -0,0 +1,17 @@
  1
+<h2>Sign in</h2>
  2
+
  3
+<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
  4
+  <div><%= f.label :email %><br />
  5
+  <%= f.email_field :email %></div>
  6
+
  7
+  <div><%= f.label :password %><br />
  8
+  <%= f.password_field :password %></div>
  9
+
  10
+  <% if devise_mapping.rememberable? -%>
  11
+    <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
  12
+  <% end -%>
  13
+
  14
+  <div><%= f.submit "Sign in" %></div>
  15
+<% end %>
  16
+
  17
+<%= render :partial => "devise/shared/links" %>
25  app/views/devise/shared/_links.erb
... ...
@@ -0,0 +1,25 @@
12  app/views/devise/unlocks/new.html.erb
... ...
@@ -0,0 +1,12 @@
  1
+<h2>Resend unlock instructions</h2>
  2
+
  3
+<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
  4
+  <%= devise_error_messages! %>
  5
+
  6
+  <div><%= f.label :email %><br />
  7
+  <%= f.email_field :email %></div>
  8
+
  9
+  <div><%= f.submit "Resend unlock instructions" %></div>
  10
+<% end %>
  11
+
  12
+<%= render :partial => "devise/shared/links" %>
5  app/views/layouts/application.html.erb
@@ -8,6 +8,11 @@
8 8
 </head>
9 9
 <body>
10 10
 
  11
+<ul class="hmenu">
  12
+  <%= render 'devise/menu/registration_items' %>
  13
+  <%= render 'devise/menu/login_items' %>
  14
+</ul>
  15
+
11 16
 <%= yield %>
12 17
 
13 18
 </body>
19  app/views/layouts/application.html.erb~
... ...
@@ -0,0 +1,19 @@
  1
+<!DOCTYPE html>
  2
+<html>
  3
+<head>
  4
+  <title>ChadV2</title>
  5
+  <%= stylesheet_link_tag    "application", :media => "all" %>
  6
+  <%= javascript_include_tag "application" %>
  7
+  <%= csrf_meta_tags %>
  8
+</head>
  9
+<body>
  10
+
  11
+<ul class="hmenu">
  12
+  <%= render 'devise/menu/registration_items' %>
  13
+  <%= render 'devise/menu/login_items' %>
  14
+</ul>
  15
+
  16
+<%= yield %>
  17
+
  18
+</body>
  19
+</html>
35  app/views/voters/_form.html.erb
... ...
@@ -0,0 +1,35 @@
  1
+<%= form_for(@voter) do |f| %>
  2
+  <% if @voter.errors.any? %>
  3
+    <div id="error_explanation">
  4
+      <h2><%= pluralize(@voter.errors.count, "error") %> prohibited this voter from being saved:</h2>
  5
+
  6
+      <ul>
  7
+      <% @voter.errors.full_messages.each do |msg| %>
  8
+        <li><%= msg %></li>
  9
+      <% end %>
  10
+      </ul>
  11
+    </div>
  12
+  <% end %>
  13
+
  14
+  <div class="field">
  15
+        <%= f.fields_for :vote do |vote| %>
  16
+
  17
+        <% @candidates.each do | candidate | %>
  18
+            
  19
+            <%= vote.radio_button :candidate_id , candidate.id %>
  20
+            <%= vote.label :candidate_id, candidate.name %>
  21
+            <br>
  22
+            
  23
+            <% end %>
  24
+
  25
+        <% end %>
  26
+  </div>
  27
+
  28
+  <div class="field">
  29
+    <%= f.label :name %><br />
  30
+    <%= f.text_field :name %>
  31
+  </div>
  32
+  <div class="actions">
  33
+    <%= f.submit %>
  34
+  </div>
  35
+<% end %>
21  app/views/voters/_form.html.erb~
... ...
@@ -0,0 +1,21 @@
  1
+<%= form_for(@voter) do |f| %>
  2
+  <% if @voter.errors.any? %>
  3
+    <div id="error_explanation">
  4
+      <h2><%= pluralize(@voter.errors.count, "error") %> prohibited this voter from being saved:</h2>
  5
+
  6
+      <ul>
  7
+      <% @voter.errors.full_messages.each do |msg| %>
  8
+        <li><%= msg %></li>
  9
+      <% end %>
  10
+      </ul>
  11
+    </div>
  12
+  <% end %>
  13
+
  14
+  <div class="field">
  15
+    <%= f.label :name %><br />
  16
+    <%= f.text_field :name %>
  17
+  </div>
  18
+  <div class="actions">
  19
+    <%= f.submit %>
  20
+  </div>
  21
+<% end %>
27  app/views/voters/admin.html.erb
... ...
@@ -0,0 +1,27 @@
  1
+<h1>Administrator</h1>
  2
+
  3
+<table>
  4
+  <tr>
  5
+    <th align="left">Voter</th>
  6
+    <th></th>
  7
+    <th></th>
  8
+    <th></th>
  9
+  </tr>
  10
+
  11
+<% @voters.each do |voter| %>
  12
+  <tr>
  13
+    <td><%= voter.name %></td>
  14
+    <td><%= link_to 'Show', voter %></td>
  15
+    <td><%= link_to 'Edit', edit_voter_path(voter) %></td>
  16
+    <td><%= link_to 'Destroy', voter, confirm: 'Are you sure?', method: :delete %></td>
  17
+  </tr>
  18
+<% end %>
  19
+</table>
  20
+
  21
+<br />
  22
+
  23
+<%= link_to 'Candidates Page', candidates_path %>
  24
+
  25
+<!-- br / -->
  26
+
  27
+<!-- %= link_to 'New Voter', new_voter_path % -->
6  app/views/voters/edit.html.erb
... ...
@@ -0,0 +1,6 @@
  1
+<h1>Editing voter</h1>
  2
+
  3
+<%= render 'form' %>
  4
+
  5
+<%= link_to 'Show', @voter %> |
  6
+<%= link_to 'Back', voters_path %>
37  app/views/voters/index.html.erb
... ...
@@ -0,0 +1,37 @@
  1
+<h1>Stats</h1>
  2
+
  3
+<table>
  4
+
  5
+<% totalvotes = @votes.count %>
  6
+
  7
+  <tr>
  8
+    <th align="left">Candidate</th>
  9
+    <th align="right">Votes</th>
  10
+    <th align="right">Percent</th>
  11
+  </tr>
  12
+
  13
+  <% @candidates.each do |candidate| %>
  14
+  <% votecount = @votes.count {|vote| vote.candidate_id == candidate.id } %> 
  15
+
  16
+  <tr>
  17
+    <td><%= candidate.name %></td>
  18
+    <td align="right"><%= votecount %></td>
  19
+    <td align="right"><%= 100 * votecount/totalvotes %>%</td>
  20
+ </tr>
  21
+
  22
+<% end %>
  23
+
  24
+</table>
  25
+</p>
  26
+
  27
+<br />
  28
+
  29
+<p>
  30
+<%= @winner %> wins!
  31
+</p>
  32
+
  33
+<!-- %= link_to "Create Account", new_voter_registration_path % -->
  34
+
  35
+<br />
  36
+
  37
+
37  app/views/voters/index.html.erb~
... ...
@@ -0,0 +1,37 @@
  1
+<h1>Stats</h1>
  2
+
  3
+<table>
  4
+
  5
+<% totalvotes = @votes.count %>
  6
+
  7
+  <tr>
  8
+    <th align="left">Candidate</th>
  9
+    <th align="right">Votes</th>
  10
+    <th align="right">Percent</th>
  11
+  </tr>
  12
+
  13
+  <% @candidates.each do |candidate| %>
  14
+  <% votecount = @votes.count {|vote| vote.candidate_id == candidate.id } %> 
  15
+
  16
+  <tr>
  17
+    <td><%= candidate.name %></td>
  18
+    <td align="right"><%= votecount %></td>
  19
+    <td align="right"><%= 100 * votecount/totalvotes %>%</td>
  20
+ </tr>
  21
+
  22
+<% end %>
  23
+
  24
+</table>
  25
+</p>
  26
+
  27
+<br />
  28
+
  29
+<p>
  30
+<%= @winner %> wins!
  31
+</p>
  32
+
  33
+<%= link_to "Create Account", new_voter_registration_path %>
  34
+
  35
+<br />
  36
+
  37
+
5  app/views/voters/new.html.erb
... ...
@@ -0,0 +1,5 @@
  1
+<h1>New voter</h1>
  2
+
  3
+<%= render 'form' %>
  4
+
  5
+<%= link_to 'Back', voters_path %>
24  app/views/voters/show.html.erb
... ...
@@ -0,0 +1,24 @@
  1
+<p id="notice"><%= notice %></p>
  2
+
  3
+<p>
  4
+  <b>Name:</b>
  5
+  <%= @voter.name %>
  6
+</p>
  7
+
  8
+
  9
+<p>
  10
+
  11
+	<b>Vote</b><br>
  12
+
  13
+	<table>
  14
+		<tr><td>Candidate ID: </td><td><%=	@voter.vote.candidate_id %></td></tr>
  15
+
  16
+		<tr><td>Candidate Name: </td><td><%=	@voter.vote.candidate.name %></td></tr>
  17
+
  18
+		<tr><td>Vote time: </td><td><%= @voter.vote.updated_at.asctime %></td></tr>
  19
+	</table>
  20
+
  21
+</p>
  22
+
  23
+<%= link_to 'Edit', edit_voter_path(@voter) %> |
  24
+<%= link_to 'Back', voters_path %>
10  app/views/voters/show.html.erb~
... ...
@@ -0,0 +1,10 @@
  1
+<p id="notice"><%= notice %></p>
  2
+
  3
+<p>
  4
+  <b>Name:</b>
  5
+  <%= @voter.name %>
  6
+</p>
  7
+
  8
+
  9
+<%= link_to 'Edit', edit_voter_path(@voter) %> |
  10
+<%= link_to 'Back', voters_path %>
21  app/views/votes/_form.html.erb
... ...
@@ -0,0 +1,21 @@
  1
+<%= form_for(@vote) do |f| %>
  2
+  <% if @vote.errors.any? %>
  3
+    <div id="error_explanation">
  4
+      <h2><%= pluralize(@vote.errors.count, "error") %> prohibited this vote from being saved:</h2>
  5
+
  6
+      <ul>
  7
+      <% @vote.errors.full_messages.each do |msg| %>
  8
+        <li><%= msg %></li>
  9
+      <% end %>
  10
+      </ul>
  11
+    </div>
  12
+  <% end %>
  13
+
  14
+  <div class="field">
  15
+    <%= f.label :name %><br />
  16
+    <%= f.text_field :name %>
  17
+  </div>
  18
+  <div class="actions">
  19
+    <%= f.submit %>
  20
+  </div>
  21
+<% end %>
6  app/views/votes/edit.html.erb
... ...
@@ -0,0 +1,6 @@
  1
+<h1>Editing vote</h1>
  2
+
  3
+<%= render 'form' %>
  4
+
  5
+<%= link_to 'Show', @vote %> |
  6
+<%= link_to 'Back', votes_path %>
23  app/views/votes/index.html.erb
... ...
@@ -0,0 +1,23 @@
  1
+<h1>Listing votes</h1>
  2
+
  3
+<table>
  4
+  <tr>
  5
+    <th>Name</th>
  6
+    <th></th>
  7
+    <th></th>
  8
+    <th></th>
  9
+  </tr>
  10
+
  11
+<% @votes.each do |vote| %>
  12
+  <tr>
  13
+    <td><%= vote.name %></td>
  14
+    <td><%= link_to 'Show', vote %></td>
  15
+    <td><%= link_to 'Edit', edit_vote_path(vote) %></td>
  16
+    <td><%= link_to 'Destroy', vote, confirm: 'Are you sure?', method: :delete %></td>
  17
+  </tr>
  18
+<% end %>
  19
+</table>
  20
+
  21
+<br />
  22
+
  23
+<%= link_to 'New Vote', new_vote_path %>
5  app/views/votes/new.html.erb
... ...
@@ -0,0 +1,5 @@
  1
+<h1>New vote</h1>
  2
+
  3
+<%= render 'form' %>
  4
+
  5
+<%= link_to 'Back', votes_path %>
10  app/views/votes/show.html.erb
... ...
@@ -0,0 +1,10 @@
  1
+<p id="notice"><%= notice %></p>
  2
+
  3
+<p>
  4
+  <b>Name:</b>
  5
+  <%= @vote.name %>
  6
+</p>
  7
+
  8
+
  9
+<%= link_to 'Edit', edit_vote_path(@vote) %> |
  10
+<%= link_to 'Back', votes_path %>
6  config/environments/development.rb
@@ -8,6 +8,12 @@
8 8
 
9 9
   # Log error messages when you accidentally call methods on nil.
10 10
   config.whiny_nils = true
  11
+  
  12
+  # Devise
  13
+  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  14
+  
  15
+  # Devise Heroku
  16
+  #config.assets.initialize_on_precompile = false
11 17
 
12 18
   # Show full error reports and disable caching
13 19
   config.consider_all_requests_local       = true
37  config/environments/development.rb~
... ...
@@ -0,0 +1,37 @@
  1
+ChadV2::Application.configure do
  2
+  # Settings specified here will take precedence over those in config/application.rb
  3
+
  4
+  # In the development environment your application's code is reloaded on
  5
+  # every request. This slows down response time but is perfect for development
  6
+  # since you don't have to restart the web server when you make code changes.
  7
+  config.cache_classes = false
  8
+
  9
+  # Log error messages when you accidentally call methods on nil.
  10
+  config.whiny_nils = true
  11
+
  12
+  # Show full error reports and disable caching
  13
+  config.consider_all_requests_local       = true
  14
+  config.action_controller.perform_caching = false
  15
+
  16
+  # Don't care if the mailer can't send
  17
+  config.action_mailer.raise_delivery_errors = false
  18
+
  19
+  # Print deprecation notices to the Rails logger
  20
+  config.active_support.deprecation = :log
  21
+
  22
+  # Only use best-standards-support built into browsers
  23
+  config.action_dispatch.best_standards_support = :builtin
  24
+
  25
+  # Raise exception on mass assignment protection for Active Record models
  26
+  config.active_record.mass_assignment_sanitizer = :strict
  27
+
  28
+  # Log the query plan for queries taking more than this (works
  29
+  # with SQLite, MySQL, and PostgreSQL)
  30
+  config.active_record.auto_explain_threshold_in_seconds = 0.5
  31
+
  32
+  # Do not compress assets
  33
+  config.assets.compress = false
  34
+
  35
+  # Expands the lines which load the assets
  36
+  config.assets.debug = true
  37
+end
218  config/initializers/devise.rb
... ...
@@ -0,0 +1,218 @@
  1
+# Use this hook to configure devise mailer, warden hooks and so forth.
  2
+# Many of these configuration options can be set straight in your model.
  3
+Devise.setup do |config|
  4
+  config.sign_out_via = :get
  5
+
  6
+  # ==> Mailer Configuration
  7
+  # Configure the e-mail address which will be shown in Devise::Mailer,
  8
+  # note that it will be overwritten if you use your own mailer class with default "from" parameter.
  9
+  config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
  10
+
  11
+  # Configure the class responsible to send e-mails.
  12
+  # config.mailer = "Devise::Mailer"
  13
+
  14
+  # ==> ORM configuration
  15
+  # Load and configure the ORM. Supports :active_record (default) and
  16
+  # :mongoid (bson_ext recommended) by default. Other ORMs may be
  17
+  # available as additional gems.
  18
+  require 'devise/orm/active_record'
  19
+
  20
+  # ==> Configuration for any authentication mechanism
  21
+  # Configure which keys are used when authenticating a user. The default is
  22
+  # just :email. You can configure it to use [:username, :subdomain], so for
  23
+  # authenticating a user, both parameters are required. Remember that those
  24
+  # parameters are used only when authenticating and not when retrieving from
  25
+  # session. If you need permissions, you should implement that in a before filter.
  26
+  # You can also supply a hash where the value is a boolean determining whether
  27
+  # or not authentication should be aborted when the value is not present.
  28
+  config.authentication_keys = [ :email ]
  29
+
  30
+  # Configure parameters from the request object used for authentication. Each entry
  31
+  # given should be a request method and it will automatically be passed to the
  32
+  # find_for_authentication method and considered in your model lookup. For instance,
  33
+  # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
  34
+  # The same considerations mentioned for authentication_keys also apply to request_keys.
  35
+  # config.request_keys = []
  36
+
  37
+  # Configure which authentication keys should be case-insensitive.
  38
+  # These keys will be downcased upon creating or modifying a user and when used
  39
+  # to authenticate or find a user. Default is :email.
  40
+  config.case_insensitive_keys = [ :email ]
  41
+
  42
+  # Configure which authentication keys should have whitespace stripped.
  43
+  # These keys will have whitespace before and after removed upon creating or
  44
+  # modifying a user and when used to authenticate or find a user. Default is :email.
  45
+  config.strip_whitespace_keys = [ :email ]
  46
+
  47
+  # Tell if authentication through request.params is enabled. True by default.
  48
+  # It can be set to an array that will enable params authentication only for the
  49
+  # given strategies, for example, `config.params_authenticatable = [:database]` will
  50
+  # enable it only for database (email + password) authentication.
  51
+  # config.params_authenticatable = true
  52
+
  53
+  # Tell if authentication through HTTP Basic Auth is enabled. False by default.
  54
+  # It can be set to an array that will enable http authentication only for the
  55
+  # given strategies, for example, `config.http_authenticatable = [:token]` will
  56
+  # enable it only for token authentication.
  57
+  # config.http_authenticatable = false
  58
+
  59
+  # If http headers should be returned for AJAX requests. True by default.
  60
+  # config.http_authenticatable_on_xhr = true
  61
+
  62
+  # The realm used in Http Basic Authentication. "Application" by default.
  63
+  # config.http_authentication_realm = "Application"
  64
+
  65
+  # It will change confirmation, password recovery and other workflows
  66
+  # to behave the same regardless if the e-mail provided was right or wrong.
  67
+  # Does not affect registerable.
  68
+  # config.paranoid = true
  69
+
  70
+  # By default Devise will store the user in session. You can skip storage for
  71
+  # :http_auth and :token_auth by adding those symbols to the array below.
  72
+  # Notice that if you are skipping storage for all authentication paths, you
  73
+  # may want to disable generating routes to Devise's sessions controller by
  74
+  # passing :skip => :sessions to `devise_for` in your config/routes.rb
  75
+  config.skip_session_storage = [:http_auth]
  76
+
  77
+  # ==> Configuration for :database_authenticatable
  78
+  # For bcrypt, this is the cost for hashing the password and defaults to 10. If
  79
+  # using other encryptors, it sets how many times you want the password re-encrypted.
  80
+  #
  81
+  # Limiting the stretches to just one in testing will increase the performance of
  82
+  # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
  83
+  # a value less than 10 in other environments.
  84
+  config.stretches = Rails.env.test? ? 1 : 10
  85
+
  86
+  # Setup a pepper to generate the encrypted password.
  87
+  # config.pepper = "34fe9dcafbfe00e16095f63f68048770e1199ac561be20d9c30ecc832858c77107fcdadde2af2ba2382d2d03e584a02d2b6ea68a4b39fd8d383795a634c3b83f"
  88
+
  89
+  # ==> Configuration for :confirmable
  90
+  # A period that the user is allowed to access the website even without
  91
+  # confirming his account. For instance, if set to 2.days, the user will be
  92
+  # able to access the website for two days without confirming his account,
  93
+  # access will be blocked just in the third day. Default is 0.days, meaning
  94
+  # the user cannot access the website without confirming his account.
  95
+  # config.allow_unconfirmed_access_for = 2.days
  96
+
  97
+  # If true, requires any email changes to be confirmed (exactly the same way as
  98
+  # initial account confirmation) to be applied. Requires additional unconfirmed_email
  99
+  # db field (see migrations). Until confirmed new email is stored in
  100
+  # unconfirmed email column, and copied to email column on successful confirmation.
  101
+  config.reconfirmable = true
  102
+
  103
+  # Defines which key will be used when confirming an account
  104
+  # config.confirmation_keys = [ :email ]
  105
+
  106
+  # ==> Configuration for :rememberable
  107
+  # The time the user will be remembered without asking for credentials again.
  108
+  # config.remember_for = 2.weeks
  109
+
  110
+  # If true, extends the user's remember period when remembered via cookie.
  111
+  # config.extend_remember_period = false
  112
+
  113
+  # Options to be passed to the created cookie. For instance, you can set
  114
+  # :secure => true in order to force SSL only cookies.
  115
+  # config.rememberable_options = {}
  116
+
  117
+  # ==> Configuration for :validatable
  118
+  # Range for password length. Default is 6..128.
  119
+  # config.password_length = 6..128
  120
+
  121
+  # Email regex used to validate email formats. It simply asserts that
  122
+  # an one (and only one) @ exists in the given string. This is mainly
  123
+  # to give user feedback and not to assert the e-mail validity.
  124
+  # config.email_regexp = /\A[^@]+@[^@]+\z/
  125
+
  126
+  # ==> Configuration for :timeoutable
  127
+  # The time you want to timeout the user session without activity. After this
  128
+  # time the user will be asked for credentials again. Default is 30 minutes.
  129
+  # config.timeout_in = 30.minutes
  130
+
  131
+  # ==> Configuration for :lockable
  132
+  # Defines which strategy will be used to lock an account.
  133
+  # :failed_attempts = Locks an account after a number of failed attempts to sign in.
  134
+  # :none            = No lock strategy. You should handle locking by yourself.
  135
+  # config.lock_strategy = :failed_attempts
  136
+
  137
+  # Defines which key will be used when locking and unlocking an account
  138
+  # config.unlock_keys = [ :email ]
  139
+
  140
+  # Defines which strategy will be used to unlock an account.
  141
+  # :email = Sends an unlock link to the user email
  142
+  # :time  = Re-enables login after a certain amount of time (see :unlock_in below)
  143
+  # :both  = Enables both strategies
  144
+  # :none  = No unlock strategy. You should handle unlocking by yourself.
  145
+  # config.unlock_strategy = :both
  146
+
  147
+  # Number of authentication tries before locking an account if lock_strategy
  148
+  # is failed attempts.
  149
+  # config.maximum_attempts = 20
  150
+
  151
+  # Time interval to unlock the account if :time is enabled as unlock_strategy.
  152
+  # config.unlock_in = 1.hour
  153
+
  154
+  # ==> Configuration for :recoverable
  155
+  #
  156
+  # Defines which key will be used when recovering the password for an account
  157
+  # config.reset_password_keys = [ :email ]
  158
+
  159
+  # Time interval you can reset your password with a reset password key.
  160
+  # Don't put a too small interval or your users won't have the time to
  161
+  # change their passwords.
  162
+  config.reset_password_within = 6.hours
  163
+
  164
+  # ==> Configuration for :encryptable
  165
+  # Allow you to use another encryption algorithm besides bcrypt (default). You can use
  166
+  # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
  167
+  # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
  168
+  # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
  169
+  # REST_AUTH_SITE_KEY to pepper)
  170
+  # config.encryptor = :sha512
  171
+
  172
+  # ==> Configuration for :token_authenticatable
  173
+  # Defines name of the authentication token params key
  174
+  # config.token_authentication_key = :auth_token
  175
+
  176
+  # ==> Scopes configuration
  177
+  # Turn scoped views on. Before rendering "sessions/new", it will first check for
  178
+  # "users/sessions/new". It's turned off by default because it's slower if you
  179
+  # are using only default views.
  180
+  # config.scoped_views = false
  181
+
  182
+  # Configure the default scope given to Warden. By default it's the first
  183
+  # devise role declared in your routes (usually :user).
  184
+  # config.default_scope = :user
  185
+
  186
+  # Configure sign_out behavior.
  187
+  # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
  188
+  # The default is true, which means any logout action will sign out all active scopes.
  189
+  # config.sign_out_all_scopes = true
  190
+
  191
+  # ==> Navigation configuration
  192
+  # Lists the formats that should be treated as navigational. Formats like
  193
+  # :html, should redirect to the sign in page when the user does not have
  194
+  # access, but formats like :xml or :json, should return 401.
  195
+  #
  196
+  # If you have any extra navigational formats, like :iphone or :mobile, you