diff --git a/Gemfile b/Gemfile
index fe8dac7..f5a85dc 100644
--- a/Gemfile
+++ b/Gemfile
@@ -41,3 +41,5 @@ gem 'bcrypt-ruby', '~> 3.0.0'
# To use debugger
# gem 'ruby-debug'
+
+gem "paperclip", "~> 3.0"
diff --git a/app/assets/javascripts/user_certifications.js.coffee b/app/assets/javascripts/user_certifications.js.coffee
new file mode 100644
index 0000000..7615679
--- /dev/null
+++ b/app/assets/javascripts/user_certifications.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/
diff --git a/app/assets/stylesheets/user_certifications.css.scss b/app/assets/stylesheets/user_certifications.css.scss
new file mode 100644
index 0000000..011a1ab
--- /dev/null
+++ b/app/assets/stylesheets/user_certifications.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the UserCertifications controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss
index 1efc835..ccaced3 100644
--- a/app/assets/stylesheets/users.css.scss
+++ b/app/assets/stylesheets/users.css.scss
@@ -1,3 +1,4 @@
// 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/
+.hoverinfo { cursor: progress; }
diff --git a/app/controllers/user_certifications_controller.rb b/app/controllers/user_certifications_controller.rb
new file mode 100644
index 0000000..728d09a
--- /dev/null
+++ b/app/controllers/user_certifications_controller.rb
@@ -0,0 +1,83 @@
+class UserCertificationsController < ApplicationController
+ # GET /user_certifications
+ # GET /user_certifications.json
+ def index
+ @user_certifications = UserCertification.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render :json => @user_certifications }
+ end
+ end
+
+ # GET /user_certifications/1
+ # GET /user_certifications/1.json
+ def show
+ @user_certification = UserCertification.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render :json => @user_certification }
+ end
+ end
+
+ # GET /user_certifications/new
+ # GET /user_certifications/new.json
+ def new
+ @user_certification = UserCertification.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render :json => @user_certification }
+ end
+ end
+
+ # GET /user_certifications/1/edit
+ def edit
+ @user_certification = UserCertification.find(params[:id])
+ end
+
+ # POST /user_certifications
+ # POST /user_certifications.json
+ def create
+ @user_certification = UserCertification.new(params[:user_certification])
+
+ respond_to do |format|
+ if @user_certification.save
+ format.html { redirect_to @user_certification, :notice => 'User certification was successfully created.' }
+ format.json { render :json => @user_certification, :status => :created, :location => @user_certification }
+ else
+ format.html { render :action => "new" }
+ format.json { render :json => @user_certification.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /user_certifications/1
+ # PUT /user_certifications/1.json
+ def update
+ @user_certification = UserCertification.find(params[:id])
+
+ respond_to do |format|
+ if @user_certification.update_attributes(params[:user_certification])
+ format.html { redirect_to @user_certification, :notice => 'User certification was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render :action => "edit" }
+ format.json { render :json => @user_certification.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /user_certifications/1
+ # DELETE /user_certifications/1.json
+ def destroy
+ @user_certification = UserCertification.find(params[:id])
+ @user_certification.destroy
+
+ respond_to do |format|
+ format.html { redirect_to user_certifications_url }
+ format.json { head :no_content }
+ end
+ end
+end
diff --git a/app/helpers/user_certifications_helper.rb b/app/helpers/user_certifications_helper.rb
new file mode 100644
index 0000000..d7bac97
--- /dev/null
+++ b/app/helpers/user_certifications_helper.rb
@@ -0,0 +1,2 @@
+module UserCertificationsHelper
+end
diff --git a/app/models/certification.rb b/app/models/certification.rb
index 665688d..3699dee 100644
--- a/app/models/certification.rb
+++ b/app/models/certification.rb
@@ -1,4 +1,5 @@
class Certification < ActiveRecord::Base
attr_accessible :description, :name
- has_many :users, :through => :certifications_users
+ has_many :user_certifications
+ has_many :users, :through => :user_certifications
end
diff --git a/app/models/user.rb b/app/models/user.rb
index a64b895..4e72376 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -6,8 +6,9 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
- attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :admin, :instructor, :active, :emergency_name, :emergency_phone, :current_skills, :desired_skills, :waiver, :emergency_email, :phone, :payment_method, :orientation, :member_level
+ attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :admin, :instructor, :active, :emergency_name, :emergency_phone, :current_skills, :desired_skills, :waiver, :emergency_email, :phone, :payment_method, :orientation, :member_level, :certifications
has_many :cards
- has_many :certifications, :through => :certifications_users
+ has_many :user_certifications
+ has_many :certifications, :through => :user_certifications
end
diff --git a/app/models/user_certification.rb b/app/models/user_certification.rb
new file mode 100644
index 0000000..25c0810
--- /dev/null
+++ b/app/models/user_certification.rb
@@ -0,0 +1,5 @@
+class UserCertification < ActiveRecord::Base
+ attr_accessible :certification_id, :user_id
+ belongs_to :user
+ belongs_to :certification
+end
diff --git a/app/views/certifications/show.html.erb b/app/views/certifications/show.html.erb
index 3b7bab1..291a316 100644
--- a/app/views/certifications/show.html.erb
+++ b/app/views/certifications/show.html.erb
@@ -11,7 +11,7 @@
Certified Users:
<% @certification.users.each do |user| %>
- <% unless user.name.blank? %>- <%= user.name %>
<% end %>
+ - <%= link_to user.name, user %>
<% end %>
<% if @certification.users.blank? then %>- n/a
<% end %>
diff --git a/app/views/user_certifications/_form.html.erb b/app/views/user_certifications/_form.html.erb
new file mode 100644
index 0000000..f07b048
--- /dev/null
+++ b/app/views/user_certifications/_form.html.erb
@@ -0,0 +1,25 @@
+<%= form_for(@user_certification) do |f| %>
+ <% if @user_certification.errors.any? %>
+
+
<%= pluralize(@user_certification.errors.count, "error") %> prohibited this user_certification from being saved:
+
+
+ <% @user_certification.errors.full_messages.each do |msg| %>
+ - <%= msg %>
+ <% end %>
+
+
+ <% end %>
+
+
+ <%= f.label :user_id %>
+ <%= f.number_field :user_id %>
+
+
+ <%= f.label :certification_id %>
+ <%= f.number_field :certification_id %>
+
+
+ <%= f.submit %>
+
+<% end %>
diff --git a/app/views/user_certifications/edit.html.erb b/app/views/user_certifications/edit.html.erb
new file mode 100644
index 0000000..ae6585d
--- /dev/null
+++ b/app/views/user_certifications/edit.html.erb
@@ -0,0 +1,6 @@
+Editing user_certification
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @user_certification %> |
+<%= link_to 'Back', user_certifications_path %>
diff --git a/app/views/user_certifications/index.html.erb b/app/views/user_certifications/index.html.erb
new file mode 100644
index 0000000..6fb97e7
--- /dev/null
+++ b/app/views/user_certifications/index.html.erb
@@ -0,0 +1,25 @@
+Listing user_certifications
+
+
+
+ User |
+ Certification |
+ |
+ |
+ |
+
+
+<% @user_certifications.each do |user_certification| %>
+
+ <%= user_certification.user_id %> |
+ <%= user_certification.certification_id %> |
+ <%= link_to 'Show', user_certification %> |
+ <%= link_to 'Edit', edit_user_certification_path(user_certification) %> |
+ <%= link_to 'Destroy', user_certification, :confirm => 'Are you sure?', :method => :delete %> |
+
+<% end %>
+
+
+
+
+<%= link_to 'New User certification', new_user_certification_path %>
diff --git a/app/views/user_certifications/new.html.erb b/app/views/user_certifications/new.html.erb
new file mode 100644
index 0000000..b0ca940
--- /dev/null
+++ b/app/views/user_certifications/new.html.erb
@@ -0,0 +1,5 @@
+New user_certification
+
+<%= render 'form' %>
+
+<%= link_to 'Back', user_certifications_path %>
diff --git a/app/views/user_certifications/show.html.erb b/app/views/user_certifications/show.html.erb
new file mode 100644
index 0000000..475c8a2
--- /dev/null
+++ b/app/views/user_certifications/show.html.erb
@@ -0,0 +1,13 @@
+
+ User:
+ <%= @user_certification.user_id %>
+
+
+
+ Certification:
+ <%= @user_certification.certification_id %>
+
+
+
+<%= link_to 'Edit', edit_user_certification_path(@user_certification) %> |
+<%= link_to 'Back', user_certifications_path %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
index 2273fa8..c2ce091 100644
--- a/app/views/users/index.html.erb
+++ b/app/views/users/index.html.erb
@@ -10,8 +10,12 @@
<% if current_user.admin? then %>
Cards |
<% end %>
+ Certifications |
Active? |
Waiver? |
+ <% if current_user.admin? then %>
+ Orientation? |
+ <% end %>
Admin? |
|
|
@@ -20,16 +24,22 @@
<% if !@users.blank? %>
<% @users.each do |user| %>
- <%= user.name %> |
+ <%= link_to user.name, user %> |
<%= user.email %> |
<% if current_user.admin? then %>
<% user.cards.each do |c| %>
<%= link_to c.card_number, card_url(c) %><%= "," unless c == user.cards.last %>
<% end %>
| <% end %>
- <%= if user.active? then "Active" end %> |
- <%= if user.waiver.blank? then "Not Signed" else "Signed" end %> |
- <%= if user.admin? then "Admin" end %> |
+ <% user.certifications.each do |c| %>
+ <%= link_to c.name, c %><%= "," unless c == user.certifications.last %>
+ <% end %> |
+ <%= if user.active? then raw("✓") end %> |
+ <%= unless user.waiver.blank? then raw("✓") end %> |
+ <% if current_user.admin? then %>
+ <%= unless user.orientation.blank? then raw("✓") end %>
+ | <% end %>
+ <%= if user.admin? then raw("✓") end %> |
<%= link_to 'Edit', edit_user_path(user) if can? :update, user %> |
<%= link_to 'Destroy', user, :confirm => 'Are you sure? WARNING: THIS DOES NOT REMOVE THE USER FROM THE DOOR SYSTEM! DISABLE THEM FIRST.', :method => :delete if can? :destroy, user %> |
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index 8cda557..3acf755 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -22,7 +22,7 @@
Certifications:
<% @user.certifications.each do |certification| %>
- - certification.name
+ - <%= link_to certification.name, certification %>
<% end %>
<% if @user.certifications.blank? %>- n/a
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index a7ee924..c71804e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,5 +1,7 @@
Dooraccess::Application.routes.draw do
+ resources :user_certifications
+
resources :certifications
devise_for :users
diff --git a/db/migrate/20130125101623_add_instructor_to_users.rb b/db/migrate/20130125101623_add_instructor_to_users.rb
new file mode 100644
index 0000000..ff65f1d
--- /dev/null
+++ b/db/migrate/20130125101623_add_instructor_to_users.rb
@@ -0,0 +1,5 @@
+class AddInstructorToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :instructor, :boolean
+ end
+end
diff --git a/db/migrate/20130125102002_create_user_certifications.rb b/db/migrate/20130125102002_create_user_certifications.rb
new file mode 100644
index 0000000..77029d4
--- /dev/null
+++ b/db/migrate/20130125102002_create_user_certifications.rb
@@ -0,0 +1,10 @@
+class CreateUserCertifications < ActiveRecord::Migration
+ def change
+ create_table :user_certifications do |t|
+ t.integer :user_id
+ t.integer :certification_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ee0c23d..2aeae4b 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121016211727) do
+ActiveRecord::Schema.define(:version => 20130125102002) do
create_table "cards", :force => true do |t|
t.string "card_number"
@@ -21,6 +21,13 @@ ActiveRecord::Schema.define(:version => 20121016211727) do
t.string "name"
end
+ create_table "certifications", :force => true do |t|
+ t.string "name"
+ t.string "description"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "door_logs", :force => true do |t|
t.string "key"
t.integer "data"
@@ -28,6 +35,13 @@ ActiveRecord::Schema.define(:version => 20121016211727) do
t.datetime "updated_at", :null => false
end
+ create_table "user_certifications", :force => true do |t|
+ t.integer "user_id"
+ t.integer "certification_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "users", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
@@ -54,6 +68,7 @@ ActiveRecord::Schema.define(:version => 20121016211727) do
t.string "phone"
t.string "current_skills"
t.string "desired_skills"
+ t.boolean "instructor"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
diff --git a/test/fixtures/user_certifications.yml b/test/fixtures/user_certifications.yml
new file mode 100644
index 0000000..9097917
--- /dev/null
+++ b/test/fixtures/user_certifications.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ user_id: 1
+ certification_id: 1
+
+two:
+ user_id: 1
+ certification_id: 1
diff --git a/test/functional/user_certifications_controller_test.rb b/test/functional/user_certifications_controller_test.rb
new file mode 100644
index 0000000..c186c7b
--- /dev/null
+++ b/test/functional/user_certifications_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class UserCertificationsControllerTest < ActionController::TestCase
+ setup do
+ @user_certification = user_certifications(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:user_certifications)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create user_certification" do
+ assert_difference('UserCertification.count') do
+ post :create, :user_certification => { :certification_id => @user_certification.certification_id, :user_id => @user_certification.user_id }
+ end
+
+ assert_redirected_to user_certification_path(assigns(:user_certification))
+ end
+
+ test "should show user_certification" do
+ get :show, :id => @user_certification
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, :id => @user_certification
+ assert_response :success
+ end
+
+ test "should update user_certification" do
+ put :update, :id => @user_certification, :user_certification => { :certification_id => @user_certification.certification_id, :user_id => @user_certification.user_id }
+ assert_redirected_to user_certification_path(assigns(:user_certification))
+ end
+
+ test "should destroy user_certification" do
+ assert_difference('UserCertification.count', -1) do
+ delete :destroy, :id => @user_certification
+ end
+
+ assert_redirected_to user_certifications_path
+ end
+end
diff --git a/test/unit/helpers/user_certifications_helper_test.rb b/test/unit/helpers/user_certifications_helper_test.rb
new file mode 100644
index 0000000..b239686
--- /dev/null
+++ b/test/unit/helpers/user_certifications_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class UserCertificationsHelperTest < ActionView::TestCase
+end
diff --git a/test/unit/user_certification_test.rb b/test/unit/user_certification_test.rb
new file mode 100644
index 0000000..f618e80
--- /dev/null
+++ b/test/unit/user_certification_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class UserCertificationTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end