Skip to content
Browse files

Committing everything for CS demo: Devise, scaffold, Rspec, etc

  • Loading branch information...
1 parent 5a4ccb9 commit 262e2524c65ad89be1035d62327881fdae33f8ad Rian Rainey committed
Showing with 2,537 additions and 13 deletions.
  1. +5 −4 Gemfile
  2. +33 −0 Gemfile.lock
  3. +46 −0 Guardfile
  4. BIN app/assets/images/Header_CommunityandIntro.jpeg
  5. +3 −0 app/assets/javascripts/application.js
  6. +3 −0 app/assets/javascripts/roles.js.coffee
  7. +11 −0 app/assets/javascripts/script.js
  8. +3 −0 app/assets/javascripts/users.js.coffee
  9. +3 −0 app/assets/javascripts/workouts.js.coffee
  10. +2 −0 app/assets/stylesheets/application.css
  11. +34 −1 app/assets/stylesheets/custom.css.scss
  12. +3 −0 app/assets/stylesheets/roles.css.scss
  13. +3 −0 app/assets/stylesheets/users.css.scss
  14. +3 −0 app/assets/stylesheets/workouts.css.scss
  15. +86 −0 app/controllers/admin/roles_controller.rb
  16. +106 −0 app/controllers/admin/users_controller.rb
  17. +86 −0 app/controllers/admin/workouts_controller.rb
  18. +2 −0 app/controllers/static_pages_controller.rb
  19. +14 −0 app/controllers/users_controller.rb
  20. +10 −0 app/controllers/workouts_controller.rb
  21. +2 −0 app/helpers/roles_helper.rb
  22. +2 −0 app/helpers/users_helper.rb
  23. +2 −0 app/helpers/workouts_helper.rb
  24. +4 −0 app/models/role.rb
  25. +31 −0 app/models/user.rb
  26. +3 −0 app/models/workout.rb
  27. +21 −0 app/views/admin/roles/_form.html.erb
  28. +6 −0 app/views/admin/roles/edit.html.erb
  29. +30 −0 app/views/admin/roles/index.html.erb
  30. +5 −0 app/views/admin/roles/new.html.erb
  31. +5 −0 app/views/admin/roles/show.html.erb
  32. +39 −0 app/views/admin/users/_form.html.erb
  33. +6 −0 app/views/admin/users/edit.html.erb
  34. +39 −0 app/views/admin/users/index.html.erb
  35. +5 −0 app/views/admin/users/new.html.erb
  36. +19 −0 app/views/admin/users/show.html.erb
  37. +29 −0 app/views/admin/workouts/_form.html.erb
  38. +6 −0 app/views/admin/workouts/edit.html.erb
  39. +31 −0 app/views/admin/workouts/index.html.erb
  40. +5 −0 app/views/admin/workouts/new.html.erb
  41. +14 −0 app/views/admin/workouts/show.html.erb
  42. +12 −0 app/views/devise/confirmations/new.html.erb
  43. +5 −0 app/views/devise/mailer/confirmation_instructions.html.erb
  44. +8 −0 app/views/devise/mailer/reset_password_instructions.html.erb
  45. +7 −0 app/views/devise/mailer/unlock_instructions.html.erb
  46. +16 −0 app/views/devise/passwords/edit.html.erb
  47. +12 −0 app/views/devise/passwords/new.html.erb
  48. +25 −0 app/views/devise/registrations/edit.html.erb
  49. +18 −0 app/views/devise/registrations/new.html.erb
  50. +17 −0 app/views/devise/sessions/new.html.erb
  51. +25 −0 app/views/devise/shared/_links.erb
  52. +12 −0 app/views/devise/unlocks/new.html.erb
  53. +6 −0 app/views/layouts/_admin_sidebar.erb
  54. +39 −3 app/views/layouts/_header.html.erb
  55. +28 −0 app/views/layouts/admin.html.erb
  56. +6 −2 app/views/layouts/application.html.erb
  57. +2 −3 app/views/static_pages/home.html.erb
  58. +19 −0 app/views/users/show.html.erb
  59. +31 −0 app/views/workouts/index.html.erb
  60. +3 −0 config/application.rb
  61. +3 −0 config/environments/development.rb
  62. +3 −0 config/environments/production.rb
  63. +232 −0 config/initializers/devise.rb
  64. +58 −0 config/locales/devise.en.yml
  65. +20 −0 config/routes.rb
  66. +11 −0 db/migrate/20121112011304_create_users.rb
  67. +10 −0 db/migrate/20121112012923_create_workouts.rb
  68. +5 −0 db/migrate/20121117060434_add_role_to_users.rb
  69. +8 −0 db/migrate/20121117061340_create_roles.rb
  70. +5 −0 db/migrate/20121117061919_add_name_to_roles.rb
  71. +5 −0 db/migrate/20121117151944_add_role_id_to_users.rb
  72. +12 −0 db/migrate/20121118145658_add_roles_users_table.rb
  73. +9 −0 db/migrate/20121120030738_remove_role_from_users.rb
  74. +9 −0 db/migrate/20121120030853_remove_role_id_from_users.rb
  75. +53 −0 db/migrate/20121123025145_add_devise_to_users.rb
  76. +54 −0 db/schema.rb
  77. +7 −0 logfile
  78. +164 −0 spec/controllers/roles_controller_spec.rb
  79. +164 −0 spec/controllers/users_controller_spec.rb
  80. +164 −0 spec/controllers/workouts_controller_spec.rb
  81. +15 −0 spec/helpers/roles_helper_spec.rb
  82. +15 −0 spec/helpers/users_helper_spec.rb
  83. +15 −0 spec/helpers/workouts_helper_spec.rb
  84. +5 −0 spec/models/role_spec.rb
  85. +17 −0 spec/models/user_spec.rb
  86. +5 −0 spec/models/workout_spec.rb
  87. +11 −0 spec/requests/roles_spec.rb
  88. +11 −0 spec/requests/users_spec.rb
  89. +11 −0 spec/requests/workouts_spec.rb
  90. +53 −0 spec/routing/roles_routing_spec.rb
  91. +53 −0 spec/routing/users_routing_spec.rb
  92. +53 −0 spec/routing/workouts_routing_spec.rb
  93. +15 −0 spec/views/roles/edit.html.erb_spec.rb
  94. +15 −0 spec/views/roles/index.html.erb_spec.rb
  95. +15 −0 spec/views/roles/new.html.erb_spec.rb
  96. +12 −0 spec/views/roles/show.html.erb_spec.rb
  97. +22 −0 spec/views/users/edit.html.erb_spec.rb
  98. +26 −0 spec/views/users/index.html.erb_spec.rb
  99. +22 −0 spec/views/users/new.html.erb_spec.rb
  100. +19 −0 spec/views/users/show.html.erb_spec.rb
  101. +20 −0 spec/views/workouts/edit.html.erb_spec.rb
  102. +23 −0 spec/views/workouts/index.html.erb_spec.rb
  103. +20 −0 spec/views/workouts/new.html.erb_spec.rb
  104. +17 −0 spec/views/workouts/show.html.erb_spec.rb
View
9 Gemfile
@@ -3,15 +3,16 @@ source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'bootstrap-sass', '2.0.4'
+gem 'pg'
-# Bundle edge Rails instead:
-# gem 'rails', :git => 'git://github.com/rails/rails.git'
+gem 'bootstrap-wysihtml5-rails'
-#gem 'sqlite3'
-gem 'pg'
+gem 'devise'
group :development do
gem 'rspec-rails'
+ gem 'annotate'
+ gem 'guard-rspec'
end
group :test do
View
33 Gemfile.lock
@@ -29,8 +29,13 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.3.2)
+ annotate (2.5.0)
+ rake
arel (3.0.2)
+ bcrypt-ruby (3.0.1)
bootstrap-sass (2.0.4.0)
+ bootstrap-wysihtml5-rails (0.3.1.10)
+ railties (>= 3.0)
builder (3.0.4)
capybara (1.1.2)
mime-types (>= 1.16)
@@ -41,6 +46,7 @@ GEM
xpath (~> 0.1.4)
childprocess (0.3.6)
ffi (~> 1.0, >= 1.0.6)
+ coderay (1.0.8)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -48,11 +54,23 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.4.0)
+ devise (2.1.2)
+ bcrypt-ruby (~> 3.0)
+ orm_adapter (~> 0.1)
+ railties (~> 3.1)
+ warden (~> 1.2.1)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
ffi (1.1.5)
+ guard (1.5.1)
+ listen (>= 0.4.2)
+ lumberjack (>= 1.0.2)
+ pry (>= 0.9.10)
+ thor (>= 0.14.6)
+ guard-rspec (1.2.1)
+ guard (>= 1.1)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
@@ -62,15 +80,23 @@ GEM
json (1.7.5)
libwebsocket (0.1.5)
addressable
+ listen (0.5.3)
+ lumberjack (1.0.2)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ method_source (0.8.1)
mime-types (1.19)
multi_json (1.3.6)
nokogiri (1.5.5)
+ orm_adapter (0.4.0)
pg (0.14.1)
polyglot (0.3.3)
+ pry (0.9.10)
+ coderay (~> 1.0.5)
+ method_source (~> 0.8)
+ slop (~> 3.3.1)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -120,6 +146,7 @@ GEM
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
+ slop (3.3.3)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
@@ -133,6 +160,8 @@ GEM
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
+ warden (1.2.1)
+ rack (>= 1.0)
xpath (0.1.4)
nokogiri (~> 1.3)
@@ -140,9 +169,13 @@ PLATFORMS
ruby
DEPENDENCIES
+ annotate
bootstrap-sass (= 2.0.4)
+ bootstrap-wysihtml5-rails
capybara
coffee-rails (~> 3.2.1)
+ devise
+ guard-rspec
jquery-rails
pg
rails (= 3.2.8)
View
46 Guardfile
@@ -0,0 +1,46 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+
+ # Turnip features and steps
+ watch(%r{^spec/acceptance/(.+)\.feature$})
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
+end
+
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+
+ # Turnip features and steps
+ watch(%r{^spec/acceptance/(.+)\.feature$})
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
+end
+
View
BIN app/assets/images/Header_CommunityandIntro.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3 app/assets/javascripts/application.js
@@ -12,4 +12,7 @@
//
//= require jquery
//= require jquery_ujs
+//= require bootstrap
+//= require bootstrap-wysihtml5
//= require_tree .
+
View
3 app/assets/javascripts/roles.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
11 app/assets/javascripts/script.js
@@ -0,0 +1,11 @@
+$(document).ready(function(){
+
+ wysihtmlfive();
+});
+
+// Apply wysihtml5 to appropriate text areas
+function wysihtmlfive() {
+ $('.wysihtml5').each(function(i, elem) {
+ $(elem).wysihtml5();
+ });
+}
View
3 app/assets/javascripts/users.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3 app/assets/javascripts/workouts.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
2 app/assets/stylesheets/application.css
@@ -9,5 +9,7 @@
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
+ *= require bootstrap-wysihtml5
*= require_tree .
*/
+
View
35 app/assets/stylesheets/custom.css.scss
@@ -1,8 +1,12 @@
// This one line includes the entire Bootstrap CSS Framework. @requires bootstrap-sass gem
@import "bootstrap";
+@import "bootstrap-responsive";
// Variables
$lightgray: #999;
+$primary-color: #51a351;
+$primary-color-secondary: #51a351;
+$btn-primary-color: $primary-color;
@mixin box_sizing {
-moz-box-sizing: border-box;
@@ -58,6 +62,10 @@ p {
line-height: 1.7em;
}
+a {
+ color: $btn-primary-color;
+}
+
/* header */
#logo {
float: left;
@@ -84,7 +92,7 @@ footer {
a {
color: #555;
&:hover {
- color: #F00;
+ color: $btn-primary-color;
}
}
small {
@@ -160,7 +168,32 @@ input, textarea, select, .uneditable-input {
@extend .error;
}
+.alert-notice {
+ background-color: #dff0d8;
+ border-color: #d6e9c6;
+ color: #468847;
+}
+
+/* Buttons */
+.btn-primary {
+ background-color: #5bb65b;
+ background-image: -moz-linear-gradient(top, #62c462, $btn-primary-color);
+ background-image: -ms-linear-gradient(top, #62c462, $btn-primary-color);
+ background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#62c462), to($btn-primary-color));
+ background-image: -webkit-linear-gradient(top, #62c462, $btn-primary-color);
+ background-image: -o-linear-gradient(top, #62c462, $btn-primary-color);
+ background-image: linear-gradient(top, #62c462, $btn-primary-color);
+ background-repeat: repeat-x;
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#FF62C462', endColorstr='#FF51A351', GradientType=0);
+ border-color: $btn-primary-color $btn-primary-color #387038;
+ border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) fadein(rgba(0, 0, 0, 0.1), 15%);
+ *background-color: $btn-primary-color;
+ filter: progid:DXImageTransform.Microsoft.gradient(enabled = false);
+}
+.btn-primary:hover, .btn-primary:active, .btn-primary.active, .btn-primary.disabled, .btn-primary[disabled] {
+ background-color: $btn-primary-color;
+}
View
3 app/assets/stylesheets/roles.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Roles controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3 app/assets/stylesheets/users.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3 app/assets/stylesheets/workouts.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Workouts controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
86 app/controllers/admin/roles_controller.rb
@@ -0,0 +1,86 @@
+class Admin::RolesController < ApplicationController
+ # GET /roles
+ # GET /roles.json
+
+ layout 'admin'
+
+ def index
+ @roles = Role.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @roles }
+ end
+ end
+
+ # GET /roles/1
+ # GET /roles/1.json
+ def show
+ @role = Role.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @role }
+ end
+ end
+
+ # GET /roles/new
+ # GET /roles/new.json
+ def new
+ @role = Role.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @role }
+ end
+ end
+
+ # GET /roles/1/edit
+ def edit
+ @role = Role.find(params[:id])
+ end
+
+ # POST /roles
+ # POST /roles.json
+ def create
+ @role = Role.new(params[:role])
+
+ respond_to do |format|
+ if @role.save
+ format.html { redirect_to admin_role_path(@role), notice: 'Role was successfully created.' }
+ format.json { render json: @role, status: :created, location: @role }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @role.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /roles/1
+ # PUT /roles/1.json
+ def update
+ @role = Role.find(params[:id])
+
+ respond_to do |format|
+ if @role.update_attributes(params[:role])
+ format.html { redirect_to admin_roles_url, notice: 'Role was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @role.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /roles/1
+ # DELETE /roles/1.json
+ def destroy
+ @role = Role.find(params[:id])
+ @role.destroy
+
+ respond_to do |format|
+ format.html { redirect_to admin_roles_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
106 app/controllers/admin/users_controller.rb
@@ -0,0 +1,106 @@
+class Admin::UsersController < ApplicationController
+ # GET /users
+ # GET /users.json
+
+ before_filter :authenticate_user!
+ before_filter :require_admin, :except => ["edit"]
+
+ layout 'admin'
+
+ def index
+ @users = User.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @users }
+ end
+ end
+
+ # GET /users/1
+ # GET /users/1.json
+ def show
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/new
+ # GET /users/new.json
+ def new
+ @user = User.new
+ @roles = Role.find(:all)
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+ # GET /users/1/edit
+ def edit
+ if current_user.id != params[:id]
+ flash[:error] = "You can only edit your own profile."
+ redirect_to :back
+ end
+
+ @user = User.find(params[:id])
+ @roles = Role.find(:all)
+
+ end
+
+ # POST /users
+ # POST /users.json
+ def create
+ @user = User.new(params[:user])
+
+ respond_to do |format|
+ if @user.save
+ format.html { redirect_to admin_users_path, notice: 'User was successfully created.' }
+ format.json { render json: @user, status: :created, location: @user }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /users/1
+ # PUT /users/1.json
+ def update
+ params[:user][:role_ids] ||= nil
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ if @user.update_attributes(params[:user])
+ format.html { redirect_to admin_users_path, notice: 'User was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @user.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.json
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+
+ respond_to do |format|
+ format.html { redirect_to admin_users_url }
+ format.json { head :no_content }
+ end
+ end
+
+ def require_admin
+ unless user_signed_in? and current_user.has_role? "Admin"
+ flash[:error] = "You must be an admin to access this section."
+ redirect_to root_path # halts request cycle
+ end
+ end
+
+end
View
86 app/controllers/admin/workouts_controller.rb
@@ -0,0 +1,86 @@
+class Admin::WorkoutsController < ApplicationController
+ # GET /workouts
+ # GET /workouts.json
+
+ layout 'admin'
+
+ def index
+ @workouts = Workout.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @workouts }
+ end
+ end
+
+ # GET /workouts/1
+ # GET /workouts/1.json
+ def show
+ @workout = Workout.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @workout }
+ end
+ end
+
+ # GET /workouts/new
+ # GET /workouts/new.json
+ def new
+ @workout = Workout.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @workout }
+ end
+ end
+
+ # GET /workouts/1/edit
+ def edit
+ @workout = Workout.find(params[:id])
+ end
+
+ # POST /workouts
+ # POST /workouts.json
+ def create
+ @workout = Workout.new(params[:workout])
+
+ respond_to do |format|
+ if @workout.save
+ format.html { redirect_to admin_workout_path(@workout), notice: 'Workout was successfully created.' }
+ format.json { render json: @workout, status: :created, location: @workout }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @workout.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /workouts/1
+ # PUT /workouts/1.json
+ def update
+ @workout = Workout.find(params[:id])
+
+ respond_to do |format|
+ if @workout.update_attributes(params[:workout])
+ format.html { redirect_to @workout, notice: 'Workout was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @workout.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /workouts/1
+ # DELETE /workouts/1.json
+ def destroy
+ @workout = Workout.find(params[:id])
+ @workout.destroy
+
+ respond_to do |format|
+ format.html { redirect_to admin_workouts_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
2 app/controllers/static_pages_controller.rb
@@ -1,5 +1,7 @@
class StaticPagesController < ApplicationController
def home
+ @user = current_user
+ @role = Role.find(1)
end
def about
View
14 app/controllers/users_controller.rb
@@ -0,0 +1,14 @@
+class UsersController < ApplicationController
+
+ # GET /users/1
+ # GET /users/1.json
+ def show
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @user }
+ end
+ end
+
+end
View
10 app/controllers/workouts_controller.rb
@@ -0,0 +1,10 @@
+class WorkoutsController < ApplicationController
+ def index
+ @workouts = Workout.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @workouts }
+ end
+ end
+end
View
2 app/helpers/roles_helper.rb
@@ -0,0 +1,2 @@
+module RolesHelper
+end
View
2 app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
+module UsersHelper
+end
View
2 app/helpers/workouts_helper.rb
@@ -0,0 +1,2 @@
+module WorkoutsHelper
+end
View
4 app/models/role.rb
@@ -0,0 +1,4 @@
+class Role < ActiveRecord::Base
+ attr_accessible :name
+ has_and_belongs_to_many :user
+end
View
31 app/models/user.rb
@@ -0,0 +1,31 @@
+# == Schema Information
+#
+# Table name: users
+#
+# id :integer not null, primary key
+# firstName :string(255)
+# lastName :string(255)
+# email :string(255)
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
+class User < ActiveRecord::Base
+ # Include default devise modules. Others available are:
+ # :token_authenticatable, :confirmable,
+ # :lockable, :timeoutable and :omniauthable
+ devise :database_authenticatable, :registerable,
+ :recoverable, :rememberable, :trackable, :validatable
+
+ # Setup accessible (or protected) attributes for your model
+ attr_accessible :email, :password, :password_confirmation, :remember_me
+ attr_accessible :firstName, :lastName, :role_ids
+ has_and_belongs_to_many :roles
+ accepts_nested_attributes_for :roles
+
+ # Check if user has a given role
+ def has_role?(*role_names)
+ self.roles.where(:name => role_names).present?
+ end
+
+end
View
3 app/models/workout.rb
@@ -0,0 +1,3 @@
+class Workout < ActiveRecord::Base
+ attr_accessible :body, :title
+end
View
21 app/views/admin/roles/_form.html.erb
@@ -0,0 +1,21 @@
+<%= form_for([:admin, @role]) do |f| %>
+ <% if @role.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@role.errors.count, "error") %> prohibited this role from being saved:</h2>
+
+ <ul>
+ <% @role.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+ </div>
+ <div class="actions">
+ <%= f.submit :class => "btn btn-primary"%>
+ </div>
+<% end %>
View
6 app/views/admin/roles/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing role</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @role %> |
+<%= link_to 'Back', admin_roles_path %>
View
30 app/views/admin/roles/index.html.erb
@@ -0,0 +1,30 @@
+<h1>Listing roles</h1>
+
+<table class="table table-striped">
+ <tr>
+ <th>Name</th>
+ <th></th>
+ </tr>
+
+<% @roles.each do |role| %>
+ <tr>
+ <td><%= role.name %></td>
+ <td>
+ <div class="btn-group">
+ <a href="#" class="btn dropdown-toggle" data-toggle="dropdown">Action<span class="caret"></span></a>
+ <ul class="dropdown-menu">
+ <li><%= link_to 'Show', admin_role_path(role) %></li>
+ <li><%= link_to 'Edit', edit_admin_role_path(role) %></li>
+ <li><%= link_to 'Destroy', admin_role_path(role), method: :delete, data: { confirm: 'Are you sure?' } %></li>
+ </ul>
+ </div>
+ </td>
+
+
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Role', new_admin_role_path %>
View
5 app/views/admin/roles/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New role</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', admin_roles_path %>
View
5 app/views/admin/roles/show.html.erb
@@ -0,0 +1,5 @@
+<p id="notice"><%= notice %></p>
+
+
+<%= link_to 'Edit', edit_admin_role_path(@role) %> |
+<%= link_to 'Back', admin_roles_path %>
View
39 app/views/admin/users/_form.html.erb
@@ -0,0 +1,39 @@
+<%= form_for([:admin, @user]) do |f| %>
+ <% if @user.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :firstName %>
+ <%= f.text_field :firstName %>
+ </div>
+ <div class="field">
+ <%= f.label :lastName %>
+ <%= f.text_field :lastName %>
+ </div>
+ <div class="field">
+ <%= f.label :email %>
+ <%= f.text_field :email %>
+ </div>
+ <div class="field">
+ <% Role.all.each do |r| %>
+ <label class="checkbox inline">
+ <%= check_box_tag "user[role_ids][]", r.id, @user.roles.include?(r) %>
+ <%= r.name %>
+ </label>
+ <% end %>
+ </div>
+
+
+ <div class="actions">
+ <%= f.submit :class => "btn btn-primary"%>
+ </div>
+<% end %>
View
6 app/views/admin/users/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', edit_admin_user_path %> |
+<%= link_to 'Back', admin_users_path %>
View
39 app/views/admin/users/index.html.erb
@@ -0,0 +1,39 @@
+<h1>Listing users</h1>
+
+<table class="table table-striped">
+ <tr>
+ <th>Firstname</th>
+ <th>Lastname</th>
+ <th>Email</th>
+ <th>Role</th>
+ <th></th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%= user.firstName %></td>
+ <td><%= user.lastName %></td>
+ <td><%= user.email %></td>
+ <td>
+ <% user.roles.each do |r| %>
+ <%= r.name %>
+ <% end %>
+ </td>
+
+ <td>
+ <div class="btn-group">
+ <a href="#" class="btn dropdown-toggle" data-toggle="dropdown">Action<span class="caret"></span></a>
+ <ul class="dropdown-menu">
+ <li><%= link_to 'Show', admin_user_path(user) %></li>
+ <li><%= link_to 'Edit', edit_admin_user_path(user) %></li>
+ <li><%= link_to 'Destroy', admin_user_path(user), method: :delete, data: { confirm: 'Are you sure?' } %></li>
+ </ul>
+ </div>
+ </td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New User', new_admin_user_path %>
View
5 app/views/admin/users/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', users_path %>
View
19 app/views/admin/users/show.html.erb
@@ -0,0 +1,19 @@
+
+<p>
+ <b>Firstname:</b>
+ <%= @user.firstName %>
+</p>
+
+<p>
+ <b>Lastname:</b>
+ <%= @user.lastName %>
+</p>
+
+<p>
+ <b>Email:</b>
+ <%= @user.email %>
+</p>
+
+
+<%= link_to 'Edit', edit_admin_user_path(@user) %> |
+<%= link_to 'Back', admin_users_path %>
View
29 app/views/admin/workouts/_form.html.erb
@@ -0,0 +1,29 @@
+<%= form_for([:admin, @workout]) do |f| %>
+ <% if @workout.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@workout.errors.count, "error") %> prohibited this workout from being saved:</h2>
+
+ <ul>
+ <% @workout.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :title %>
+ <%= f.text_field :title %>
+ </div>
+ <div class="field">
+ <%= f.label :body %>
+ <%= f.text_area :body, :placeholder => "Enter workout description here...", :class => "wysihtml5" %>
+ </div>
+ <div class="actions">
+ <%= f.submit :class => "btn btn-primary" %>
+ </div>
+<% end %>
+
+<script type="text/javascript">
+
+</script>
View
6 app/views/admin/workouts/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing workout</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @workout %> |
+<%= link_to 'Back', admin_workouts_path %>
View
31 app/views/admin/workouts/index.html.erb
@@ -0,0 +1,31 @@
+<h1>Listing workouts</h1>
+
+<table class="table table-striped">
+ <tr>
+ <th>Title</th>
+ <th>Body</th>
+ <th></th>
+ </tr>
+
+<% @workouts.each do |workout| %>
+ <tr>
+ <td><%= workout.title %></td>
+ <td><%= workout.body %></td>
+ <td>
+ <div class="btn-group">
+ <a href="#" class="btn dropdown-toggle" data-toggle="dropdown">Action<span class="caret"></span></a>
+ <ul class="dropdown-menu">
+ <li><%= link_to 'Show', admin_workout_path(workout) %></li>
+ <li><%= link_to 'Edit', edit_admin_workout_path(workout) %></li>
+ <li><%= link_to 'Destroy', admin_workout_path(workout), method: :delete, data: { confirm: 'Are you sure?' } %></li>
+ </ul>
+ </div>
+ </td>
+
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Workout', new_admin_workout_path %>
View
5 app/views/admin/workouts/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New workout</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', admin_workouts_path %>
View
14 app/views/admin/workouts/show.html.erb
@@ -0,0 +1,14 @@
+
+<p>
+ <b>Title:</b>
+ <%= @workout.title %>
+</p>
+
+<p>
+ <b>Body:</b>
+ <%= @workout.body %>
+</p>
+
+
+<%= link_to 'Edit', edit_admin_workout_path(@workout) %> |
+<%= link_to 'Back', admin_workouts_path %>
View
12 app/views/devise/confirmations/new.html.erb
@@ -0,0 +1,12 @@
+<h2>Resend confirmation instructions</h2>
+
+<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
+ <%= devise_error_messages! %>
+
+ <div><%= f.label :email %><br />
+ <%= f.email_field :email %></div>
+
+ <div><%= f.submit "Resend confirmation instructions" %></div>
+<% end %>
+
+<%= render "devise/shared/links" %>
View
5 app/views/devise/mailer/confirmation_instructions.html.erb
@@ -0,0 +1,5 @@
+<p>Welcome <%= @resource.email %>!</p>
+
+<p>You can confirm your account email through the link below:</p>
+
+<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
View
8 app/views/devise/mailer/reset_password_instructions.html.erb
@@ -0,0 +1,8 @@
+<p>Hello <%= @resource.email %>!</p>
+
+<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
+
+<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
+
+<p>If you didn't request this, please ignore this email.</p>
+<p>Your password won't change until you access the link above and create a new one.</p>
View
7 app/views/devise/mailer/unlock_instructions.html.erb
@@ -0,0 +1,7 @@
+<p>Hello <%= @resource.email %>!</p>
+
+<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
+
+<p>Click the link below to unlock your account:</p>
+
+<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
View
16 app/views/devise/passwords/edit.html.erb
@@ -0,0 +1,16 @@
+<h2>Change your password</h2>
+
+<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
+ <%= devise_error_messages! %>
+ <%= f.hidden_field :reset_password_token %>
+
+ <div><%= f.label :password, "New password" %><br />
+ <%= f.password_field :password %></div>
+
+ <div><%= f.label :password_confirmation, "Confirm new password" %><br />
+ <%= f.password_field :password_confirmation %></div>
+
+ <div><%= f.submit "Change my password" %></div>
+<% end %>
+
+<%= render "devise/shared/links" %>
View
12 app/views/devise/passwords/new.html.erb
@@ -0,0 +1,12 @@
+<h2>Forgot your password?</h2>
+
+<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
+ <%= devise_error_messages! %>
+
+ <div><%= f.label :email %><br />
+ <%= f.email_field :email %></div>
+
+ <div><%= f.submit "Send me reset password instructions" %></div>
+<% end %>
+
+<%= render "devise/shared/links" %>
View
25 app/views/devise/registrations/edit.html.erb
@@ -0,0 +1,25 @@
+<h2>Edit <%= resource_name.to_s.humanize %></h2>
+
+<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
+ <%= devise_error_messages! %>
+
+ <div><%= f.label :email %><br />
+ <%= f.email_field :email %></div>
+
+ <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
+ <%= f.password_field :password, :autocomplete => "off" %></div>
+
+ <div><%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %></div>
+
+ <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
+ <%= f.password_field :current_password %></div>
+
+ <div><%= f.submit "Update" %></div>
+<% end %>
+
+<h3>Cancel my account</h3>
+
+<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.</p>
+
+<%= link_to "Back", :back %>
View
18 app/views/devise/registrations/new.html.erb
@@ -0,0 +1,18 @@
+<h2>Sign up</h2>
+
+<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
+ <%= devise_error_messages! %>
+
+ <div><%= f.label :email %><br />
+ <%= f.email_field :email %></div>
+
+ <div><%= f.label :password %><br />
+ <%= f.password_field :password %></div>
+
+ <div><%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %></div>
+
+ <div><%= f.submit "Sign up" %></div>
+<% end %>
+
+<%= render "devise/shared/links" %>
View
17 app/views/devise/sessions/new.html.erb
@@ -0,0 +1,17 @@
+<h2>Sign in</h2>
+
+<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
+ <div><%= f.label :email %><br />
+ <%= f.email_field :email %></div>
+
+ <div><%= f.label :password %><br />
+ <%= f.password_field :password %></div>
+
+ <% if devise_mapping.rememberable? -%>
+ <div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
+ <% end -%>
+
+ <div><%= f.submit "Sign in" %></div>
+<% end %>
+
+<%= render "devise/shared/links" %>
View
25 app/views/devise/shared/_links.erb
@@ -0,0 +1,25 @@
+<%- if controller_name != 'sessions' %>
+ <%= link_to "Sign in", new_session_path(resource_name) %><br />
+<% end -%>
+
+<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
+ <%= link_to "Sign up", new_registration_path(resource_name) %><br />
+<% end -%>
+
+<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
+ <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
+<% end -%>
+
+<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
+ <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
+<% end -%>
+
+<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
+ <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
+<% end -%>
+
+<%- if devise_mapping.omniauthable? %>
+ <%- resource_class.omniauth_providers.each do |provider| %>
+ <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
+ <% end -%>
+<% end -%>
View
12 app/views/devise/unlocks/new.html.erb
@@ -0,0 +1,12 @@
+<h2>Resend unlock instructions</h2>
+
+<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
+ <%= devise_error_messages! %>
+
+ <div><%= f.label :email %><br />
+ <%= f.email_field :email %></div>
+
+ <div><%= f.submit "Resend unlock instructions" %></div>
+<% end %>
+
+<%= render "devise/shared/links" %>
View
6 app/views/layouts/_admin_sidebar.erb
@@ -0,0 +1,6 @@
+<ul class="nav nav-list">
+ <li class="nav-header">Admin</li>
+ <li><%= link_to "Users", admin_users_path %></li>
+ <li><%= link_to "Workouts", admin_workouts_path %></li>
+ <li><%= link_to "User Roles", admin_roles_path %></li>
+</ul>
View
42 app/views/layouts/_header.html.erb
@@ -2,12 +2,48 @@
<div class="navbar-inner">
<div class="container">
<%= link_to "CrossFit West Nashville", root_path, id: "logo" %>
- <nav>
+ <div class="navbar">
<ul class="nav pull-right">
+
<li><%= link_to "Home", root_path %></li>
- <li><%= link_to "About", about_path %></li>
+
+ <% if user_signed_in? # Devise function %>
+ <li><%= link_to "Workouts", workouts_index_path %></li>
+ <li class="dropdown">
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">Me<b class="caret"></b></a>
+ <ul class="dropdown-menu">
+ <li><%= link_to "My Profile", user_path(current_user) %></li>
+ <li class="divider"></li>
+ <li>
+ <%= link_to "Log Out", destroy_user_session_path,
+ :method => :delete,
+ :tabindex => "-1" %>
+ </li>
+
+ </ul>
+ </li>
+
+
+ <% if current_user.has_role? "Admin" %>
+ <div class="btn-group" style="float:left; display:inline;">
+ <a class="btn btn-success dropdown-toggle" data-toggle="dropdown" href="#">
+ Admin
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu">
+ <li><%= link_to "Users", admin_users_path %></li>
+ </ul>
+ </div>
+ <% end %>
+
+ <% else %>
+ <li><%= link_to "Register", new_user_registration_path %></li>
+ <li><%= link_to "Sign In", new_user_session_path %></li>
+ <% end %>
+
+
</ul>
- </nav>
+ </div>
</div>
</div>
</header>
View
28 app/views/layouts/admin.html.erb
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CrossFit West Nashville</title>
+ <%= stylesheet_link_tag "application", :media => "all" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
+ <!--[ if lt IE 9]><script src ="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![ endif]-->
+</head>
+<body>
+ <%= render 'layouts/header' %>
+ <div class="container">
+ <% flash.each do |key, value| %>
+ <div class="alert alert-<%= key %>"><%= value %></div>
+ <% end %>
+
+ <div class="row">
+ <div class="span3"><%= render 'layouts/admin_sidebar' %></div>
+ <div class="span9"><%= yield %></div>
+ </div>
+
+ <%= render 'layouts/footer' %>
+
+ <%= debug(params) if Rails.env.development? %>
+ </div>
+
+</body>
+</html>
View
8 app/views/layouts/application.html.erb
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>CfwnApp</title>
+ <title>CrossFit West Nashville</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
@@ -10,10 +10,14 @@
<body>
<%= render 'layouts/header' %>
<div class="container">
+ <% flash.each do |key, value| %>
+ <div class="alert alert-<%= key %>"><%= value %></div>
+ <% end %>
+
<%= yield %>
<%= render 'layouts/footer' %>
-
+
<%= debug(params) if Rails.env.development? %>
</div>
View
5 app/views/static_pages/home.html.erb
@@ -1,5 +1,4 @@
-<div class="center hero-unit">
- <h1>StaticPages#home</h1>
- <p>Find me in app/views/static_pages/home.html.erb</p>
+<div class="center">
+ <%= image_tag("Header_CommunityandIntro.jpeg") %>
</div>
View
19 app/views/users/show.html.erb
@@ -0,0 +1,19 @@
+
+<p>
+ <b>Firstname:</b>
+ <%= @user.firstName %>
+</p>
+
+<p>
+ <b>Lastname:</b>
+ <%= @user.lastName %>
+</p>
+
+<p>
+ <b>Email:</b>
+ <%= @user.email %>
+</p>
+
+
+<%= link_to 'Edit', edit_admin_user_path(@user) %> |
+<%= link_to 'Back', admin_users_path %>
View
31 app/views/workouts/index.html.erb
@@ -0,0 +1,31 @@
+<h1>Listing workouts</h1>
+
+<table class="table table-striped">
+ <tr>
+ <th>Title</th>
+ <th>Body</th>
+ <th></th>
+ </tr>
+
+<% @workouts.each do |workout| %>
+ <tr>
+ <td><%= workout.title %></td>
+ <td><%= workout.body %></td>
+ <td>
+ <div class="btn-group">
+ <a href="#" class="btn dropdown-toggle" data-toggle="dropdown">Action<span class="caret"></span></a>
+ <ul class="dropdown-menu">
+ <li><%= link_to 'Show', admin_workout_path(workout) %></li>
+ <li><%= link_to 'Edit', edit_admin_workout_path(workout) %></li>
+ <li><%= link_to 'Destroy', admin_workout_path(workout), method: :delete, data: { confirm: 'Are you sure?' } %></li>
+ </ul>
+ </div>
+ </td>
+
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Workout', new_admin_workout_path %>
View
3 config/application.rb
@@ -64,5 +64,8 @@ class Application < Rails::Application
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
+
+ # Devise
+ config.assets.initialize_on_precompile = false
end
end
View
3 config/environments/development.rb
@@ -34,4 +34,7 @@
# Expands the lines which load the assets
config.assets.debug = true
+
+ # Devise
+ config.action_mailer.default_url_options = { :host => 'localhost:3001' }
end
View
3 config/environments/production.rb
@@ -64,4 +64,7 @@
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
+ #
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
+ config.assets.precompile += %w( bootstrap-wysihtml5/wysiwyg-color.css )
end
View
232 config/initializers/devise.rb
@@ -0,0 +1,232 @@
+# Use this hook to configure devise mailer, warden hooks and so forth.
+# Many of these configuration options can be set straight in your model.
+Devise.setup do |config|
+ # ==> Mailer Configuration
+ # Configure the e-mail address which will be shown in Devise::Mailer,
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
+ config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
+
+ # Configure the class responsible to send e-mails.
+ # config.mailer = "Devise::Mailer"
+
+ # ==> ORM configuration
+ # Load and configure the ORM. Supports :active_record (default) and
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
+ # available as additional gems.
+ require 'devise/orm/active_record'
+
+ # ==> Configuration for any authentication mechanism
+ # Configure which keys are used when authenticating a user. The default is
+ # just :email. You can configure it to use [:username, :subdomain], so for
+ # authenticating a user, both parameters are required. Remember that those
+ # parameters are used only when authenticating and not when retrieving from
+ # session. If you need permissions, you should implement that in a before filter.
+ # You can also supply a hash where the value is a boolean determining whether
+ # or not authentication should be aborted when the value is not present.
+ # config.authentication_keys = [ :email ]
+
+ # Configure parameters from the request object used for authentication. Each entry
+ # given should be a request method and it will automatically be passed to the
+ # find_for_authentication method and considered in your model lookup. For instance,
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
+ # config.request_keys = []
+
+ # Configure which authentication keys should be case-insensitive.
+ # These keys will be downcased upon creating or modifying a user and when used
+ # to authenticate or find a user. Default is :email.
+ config.case_insensitive_keys = [ :email ]
+
+ # Configure which authentication keys should have whitespace stripped.
+ # These keys will have whitespace before and after removed upon creating or
+ # modifying a user and when used to authenticate or find a user. Default is :email.
+ config.strip_whitespace_keys = [ :email ]
+
+ # Tell if authentication through request.params is enabled. True by default.
+ # It can be set to an array that will enable params authentication only for the
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
+ # enable it only for database (email + password) authentication.
+ # config.params_authenticatable = true
+
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
+ # It can be set to an array that will enable http authentication only for the
+ # given strategies, for example, `config.http_authenticatable = [:token]` will
+ # enable it only for token authentication.
+ # config.http_authenticatable = false
+
+ # If http headers should be returned for AJAX requests. True by default.
+ # config.http_authenticatable_on_xhr = true
+
+ # The realm used in Http Basic Authentication. "Application" by default.
+ # config.http_authentication_realm = "Application"
+
+ # It will change confirmation, password recovery and other workflows
+ # to behave the same regardless if the e-mail provided was right or wrong.
+ # Does not affect registerable.
+ # config.paranoid = true
+
+ # By default Devise will store the user in session. You can skip storage for
+ # :http_auth and :token_auth by adding those symbols to the array below.
+ # Notice that if you are skipping storage for all authentication paths, you
+ # may want to disable generating routes to Devise's sessions controller by
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
+ config.skip_session_storage = [:http_auth]
+
+ # ==> Configuration for :database_authenticatable
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
+ # using other encryptors, it sets how many times you want the password re-encrypted.
+ #
+ # Limiting the stretches to just one in testing will increase the performance of
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
+ # a value less than 10 in other environments.
+ config.stretches = Rails.env.test? ? 1 : 10
+
+ # Setup a pepper to generate the encrypted password.
+ # config.pepper = "8af95cc7325032f863cf7ef07ea00d4abc1745c64ec2ed9e81aff050c6b6f2bfbb7f2521d2aae202a261c95e5adf73af422bab432a51f6df329a3079ea2c8f8b"
+
+ # ==> Configuration for :confirmable
+ # A period that the user is allowed to access the website even without
+ # confirming his account. For instance, if set to 2.days, the user will be
+ # able to access the website for two days without confirming his account,
+ # access will be blocked just in the third day. Default is 0.days, meaning
+ # the user cannot access the website without confirming his account.
+ # config.allow_unconfirmed_access_for = 2.days
+
+ # If true, requires any email changes to be confirmed (exactly the same way as
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
+ # db field (see migrations). Until confirmed new email is stored in
+ # unconfirmed email column, and copied to email column on successful confirmation.
+ config.reconfirmable = true
+
+ # Defines which key will be used when confirming an account
+ # config.confirmation_keys = [ :email ]
+
+ # ==> Configuration for :rememberable
+ # The time the user will be remembered without asking for credentials again.
+ # config.remember_for = 2.weeks
+
+ # If true, extends the user's remember period when remembered via cookie.
+ # config.extend_remember_period = false
+
+ # Options to be passed to the created cookie. For instance, you can set
+ # :secure => true in order to force SSL only cookies.
+ # config.rememberable_options = {}
+
+ # ==> Configuration for :validatable
+ # Range for password length. Default is 6..128.
+ # config.password_length = 6..128
+
+ # Email regex used to validate email formats. It simply asserts that
+ # an one (and only one) @ exists in the given string. This is mainly
+ # to give user feedback and not to assert the e-mail validity.
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
+
+ # ==> Configuration for :timeoutable
+ # The time you want to timeout the user session without activity. After this
+ # time the user will be asked for credentials again. Default is 30 minutes.
+ # config.timeout_in = 30.minutes
+
+ # If true, expires auth token on session timeout.
+ # config.expire_auth_token_on_timeout = false
+
+ # ==> Configuration for :lockable
+ # Defines which strategy will be used to lock an account.
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
+ # :none = No lock strategy. You should handle locking by yourself.
+ # config.lock_strategy = :failed_attempts
+
+ # Defines which key will be used when locking and unlocking an account
+ # config.unlock_keys = [ :email ]
+
+ # Defines which strategy will be used to unlock an account.
+ # :email = Sends an unlock link to the user email
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
+ # :both = Enables both strategies
+ # :none = No unlock strategy. You should handle unlocking by yourself.
+ # config.unlock_strategy = :both
+
+ # Number of authentication tries before locking an account if lock_strategy
+ # is failed attempts.
+ # config.maximum_attempts = 20
+
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
+ # config.unlock_in = 1.hour
+
+ # ==> Configuration for :recoverable
+ #
+ # Defines which key will be used when recovering the password for an account
+ # config.reset_password_keys = [ :email ]
+
+ # Time interval you can reset your password with a reset password key.
+ # Don't put a too small interval or your users won't have the time to
+ # change their passwords.
+ config.reset_password_within = 6.hours
+
+ # ==> Configuration for :encryptable
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
+ # REST_AUTH_SITE_KEY to pepper)
+ # config.encryptor = :sha512
+
+ # ==> Configuration for :token_authenticatable
+ # Defines name of the authentication token params key
+ # config.token_authentication_key = :auth_token
+
+ # ==> Scopes configuration
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
+ # "users/sessions/new". It's turned off by default because it's slower if you
+ # are using only default views.
+ # config.scoped_views = false
+
+ # Configure the default scope given to Warden. By default it's the first
+ # devise role declared in your routes (usually :user).
+ # config.default_scope = :user
+
+ # Set this configuration to false if you want /users/sign_out to sign out
+ # only the current scope. By default, Devise signs out all scopes.
+ # config.sign_out_all_scopes = true
+
+ # ==> Navigation configuration
+ # Lists the formats that should be treated as navigational. Formats like
+ # :html, should redirect to the sign in page when the user does not have
+ # access, but formats like :xml or :json, should return 401.
+ #
+ # If you have any extra navigational formats, like :iphone or :mobile, you
+ # should add them to the navigational formats lists.
+ #
+ # The "*/*" below is required to match Internet Explorer requests.
+ # config.navigational_formats = ["*/*", :html]
+
+ # The default HTTP method used to sign out a resource. Default is :delete.
+ config.sign_out_via = :delete
+
+ # ==> OmniAuth
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
+ # up on your models and hooks.
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
+
+ # ==> Warden configuration
+ # If you want to use other strategies, that are not supported by Devise, or
+ # change the failure app, you can configure them inside the config.warden block.
+ #
+ # config.warden do |manager|
+ # manager.intercept_401 = false
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
+ # end
+
+ # ==> Mountable engine configurations
+ # When using Devise inside an engine, let's call it `MyEngine`, and this engine
+ # is mountable, there are some extra configurations to be taken into account.
+ # The following options are available, assuming the engine is mounted as:
+ #
+ # mount MyEngine, at: "/my_engine"
+ #
+ # The router that invoked `devise_for`, in the example above, would be:
+ # config.router_name = :my_engine
+ #
+ # When using omniauth, Devise cannot automatically set Omniauth path,
+ # so you need to do it manually. For the users scope, it would be:
+ # config.omniauth_path_prefix = "/my_engine/users/auth"
+end
View
58 config/locales/devise.en.yml
@@ -0,0 +1,58 @@
+# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
+
+en:
+ errors:
+ messages:
+ expired: "has expired, please request a new one"
+ not_found: "not found"
+ already_confirmed: "was already confirmed, please try signing in"
+ not_locked: "was not locked"
+ not_saved:
+ one: "1 error prohibited this %{resource} from being saved:"
+ other: "%{count} errors prohibited this %{resource} from being saved:"
+
+ devise:
+ failure:
+ already_authenticated: 'You are already signed in.'
+ unauthenticated: 'You need to sign in or sign up before continuing.'
+ unconfirmed: 'You have to confirm your account before continuing.'
+ locked: 'Your account is locked.'
+ invalid: 'Invalid email or password.'
+ invalid_token: 'Invalid authentication token.'
+ timeout: 'Your session expired, please sign in again to continue.'
+ inactive: 'Your account was not activated yet.'
+ sessions:
+ signed_in: 'Signed in successfully.'
+ signed_out: 'Signed out successfully.'
+ passwords:
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
+ updated: 'Your password was changed successfully. You are now signed in.'
+ updated_not_active: 'Your password was changed successfully.'
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
+ confirmations:
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
+ send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
+ registrations:
+ signed_up: 'Welcome! You have signed up successfully.'
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
+ updated: 'You updated your account successfully.'
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
+ unlocks:
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
+ omniauth_callbacks:
+ success: 'Successfully authenticated from %{kind} account.'
+ failure: 'Could not authenticate you from %{kind} because "%{reason}".'
+ mailer:
+ confirmation_instructions:
+ subject: 'Confirmation instructions'
+ reset_password_instructions:
+ subject: 'Reset password instructions'
+ unlock_instructions:
+ subject: 'Unlock Instructions'
View
20 config/routes.rb
@@ -1,9 +1,29 @@
CfwnApp::Application.routes.draw do
+ devise_for :users
+
+ get "workouts/index"
+
+ #resources :workouts
+
+ resources :users, :only => [:show]
+
# Static Pages
root to: 'static_pages#home'
match '/about', to: 'static_pages#about'
+ namespace :admin do
+ resources :users, :except => [:show]
+ resources :workouts, :roles
+ end
+
+ # Sample resource route within a namespace:
+ # namespace :admin do
+ # # Directs /admin/products/* to Admin::ProductsController
+ # # (app/controllers/admin/products_controller.rb)
+ # resources :products
+ # end
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
11 db/migrate/20121112011304_create_users.rb
@@ -0,0 +1,11 @@
+class CreateUsers < ActiveRecord::Migration
+ def change
+ create_table :users do |t|
+ t.string :firstName
+ t.string :lastName
+ t.string :email
+
+ t.timestamps
+ end
+ end
+end
View
10 db/migrate/20121112012923_create_workouts.rb
@@ -0,0 +1,10 @@
+class CreateWorkouts < ActiveRecord::Migration
+ def change
+ create_table :workouts do |t|
+ t.string :title
+ t.text :body
+
+ t.timestamps
+ end
+ end
+end
View
5 db/migrate/20121117060434_add_role_to_users.rb
@@ -0,0 +1,5 @@
+class AddRoleToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :role, :string
+ end
+end
View
8 db/migrate/20121117061340_create_roles.rb
@@ -0,0 +1,8 @@
+class CreateRoles < ActiveRecord::Migration
+ def change
+ create_table :roles do |t|
+
+ t.timestamps
+ end
+ end
+end
View
5 db/migrate/20121117061919_add_name_to_roles.rb
@@ -0,0 +1,5 @@
+class AddNameToRoles < ActiveRecord::Migration
+ def change
+ add_column :roles, :name, :string
+ end
+end
View
5 db/migrate/20121117151944_add_role_id_to_users.rb
@@ -0,0 +1,5 @@
+class AddRoleIdToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :role_id, :integer
+ end
+end
View
12 db/migrate/20121118145658_add_roles_users_table.rb
@@ -0,0 +1,12 @@
+class AddRolesUsersTable < ActiveRecord::Migration
+ def up
+ create_table :roles_users, :id => false do |t|
+ t.integer :role_id
+ t.integer :user_id
+ end
+ end
+
+ def down
+ drop_table :roles_users
+ end
+end
View
9 db/migrate/20121120030738_remove_role_from_users.rb
@@ -0,0 +1,9 @@
+class RemoveRoleFromUsers < ActiveRecord::Migration
+ def up
+ remove_column :users, :role
+ end
+
+ def down
+ add_column :users, :role, :string
+ end
+end
View
9 db/migrate/20121120030853_remove_role_id_from_users.rb
@@ -0,0 +1,9 @@
+class RemoveRoleIdFromUsers < ActiveRecord::Migration
+ def up
+ remove_column :users, :role_id
+ end
+
+ def down
+ add_column :users, :role_id, :integer
+ end
+end
View
53 db/migrate/20121123025145_add_devise_to_users.rb
@@ -0,0 +1,53 @@
+class AddDeviseToUsers < ActiveRecord::Migration
+ def self.up
+ change_table(:users) do |t|
+ ## Database authenticatable
+ #t.string :email, :null => false, :default => ""
+ t.string :encrypted_password, :null => false, :default => ""
+
+ ## Recoverable
+ t.string :reset_password_token
+ t.datetime :reset_password_sent_at
+
+ ## Rememberable
+ t.datetime :remember_created_at
+
+ ## Trackable
+ t.integer :sign_in_count, :default => 0
+ t.datetime :current_sign_in_at
+ t.datetime :last_sign_in_at
+ t.string :current_sign_in_ip
+ t.string :last_sign_in_ip
+
+ ## Confirmable
+ # t.string :confirmation_token
+ # t.datetime :confirmed_at
+ # t.datetime :confirmation_sent_at
+ # t.string :unconfirmed_email # Only if using reconfirmable
+
+ ## Lockable
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
+ # t.datetime :locked_at
+
+ ## Token authenticatable
+ # t.string :authentication_token
+
+
+ # Uncomment below if timestamps were not included in your original model.
+ # t.timestamps
+ end
+
+ add_index :users, :email, :unique => true
+ add_index :users, :reset_password_token, :unique => true
+ # add_index :users, :confirmation_token, :unique => true
+ # add_index :users, :unlock_token, :unique => true
+ # add_index :users, :authentication_token, :unique => true
+ end
+
+ def self.down
+ # By default, we don't want to make any assumption about how to roll back a migration when your
+ # model already existed. Please edit below which fields you would like to remove in this migration.
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
View
54 db/schema.rb
@@ -0,0 +1,54 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20121123025145) do
+
+ create_table "roles", :force => true do |t|
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "name"
+ end
+
+ create_table "roles_users", :id => false, :force => true do |t|
+ t.integer "role_id"
+ t.integer "user_id"
+ end
+
+ create_table "users", :force => true do |t|
+ t.string "firstName"
+ t.string "lastName"
+ t.string "email"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "encrypted_password", :default => "", :null => false
+ t.string "reset_password_token"
+ t.datetime "reset_password_sent_at"
+ t.datetime "remember_created_at"
+ t.integer "sign_in_count", :default => 0
+ t.datetime "current_sign_in_at"
+ t.datetime "last_sign_in_at"
+ t.string "current_sign_in_ip"
+ t.string "last_sign_in_ip"
+ end
+
+ add_index "users", ["email"], :name => "index_users_on_email", :unique => true
+ add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true