Adding user_certifications relation, and paperclip gem
This commit is contained in:
3
app/assets/javascripts/user_certifications.js.coffee
Normal file
3
app/assets/javascripts/user_certifications.js.coffee
Normal file
@@ -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/
|
||||
3
app/assets/stylesheets/user_certifications.css.scss
Normal file
3
app/assets/stylesheets/user_certifications.css.scss
Normal file
@@ -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/
|
||||
@@ -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; }
|
||||
|
||||
83
app/controllers/user_certifications_controller.rb
Normal file
83
app/controllers/user_certifications_controller.rb
Normal file
@@ -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
|
||||
2
app/helpers/user_certifications_helper.rb
Normal file
2
app/helpers/user_certifications_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module UserCertificationsHelper
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
5
app/models/user_certification.rb
Normal file
5
app/models/user_certification.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class UserCertification < ActiveRecord::Base
|
||||
attr_accessible :certification_id, :user_id
|
||||
belongs_to :user
|
||||
belongs_to :certification
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
<b>Certified Users:</b>
|
||||
<ul>
|
||||
<% @certification.users.each do |user| %>
|
||||
<% unless user.name.blank? %><li><%= user.name %></li><% end %>
|
||||
<li><%= link_to user.name, user %></li>
|
||||
<% end %>
|
||||
<% if @certification.users.blank? then %><li>n/a</li><% end %>
|
||||
</ul>
|
||||
|
||||
25
app/views/user_certifications/_form.html.erb
Normal file
25
app/views/user_certifications/_form.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<%= form_for(@user_certification) do |f| %>
|
||||
<% if @user_certification.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(@user_certification.errors.count, "error") %> prohibited this user_certification from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% @user_certification.errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="field">
|
||||
<%= f.label :user_id %><br />
|
||||
<%= f.number_field :user_id %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= f.label :certification_id %><br />
|
||||
<%= f.number_field :certification_id %>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<%= f.submit %>
|
||||
</div>
|
||||
<% end %>
|
||||
6
app/views/user_certifications/edit.html.erb
Normal file
6
app/views/user_certifications/edit.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<h1>Editing user_certification</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Show', @user_certification %> |
|
||||
<%= link_to 'Back', user_certifications_path %>
|
||||
25
app/views/user_certifications/index.html.erb
Normal file
25
app/views/user_certifications/index.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<h1>Listing user_certifications</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Certification</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
<% @user_certifications.each do |user_certification| %>
|
||||
<tr>
|
||||
<td><%= user_certification.user_id %></td>
|
||||
<td><%= user_certification.certification_id %></td>
|
||||
<td><%= link_to 'Show', user_certification %></td>
|
||||
<td><%= link_to 'Edit', edit_user_certification_path(user_certification) %></td>
|
||||
<td><%= link_to 'Destroy', user_certification, :confirm => 'Are you sure?', :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New User certification', new_user_certification_path %>
|
||||
5
app/views/user_certifications/new.html.erb
Normal file
5
app/views/user_certifications/new.html.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>New user_certification</h1>
|
||||
|
||||
<%= render 'form' %>
|
||||
|
||||
<%= link_to 'Back', user_certifications_path %>
|
||||
13
app/views/user_certifications/show.html.erb
Normal file
13
app/views/user_certifications/show.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<p>
|
||||
<b>User:</b>
|
||||
<%= @user_certification.user_id %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Certification:</b>
|
||||
<%= @user_certification.certification_id %>
|
||||
</p>
|
||||
|
||||
|
||||
<%= link_to 'Edit', edit_user_certification_path(@user_certification) %> |
|
||||
<%= link_to 'Back', user_certifications_path %>
|
||||
@@ -10,8 +10,12 @@
|
||||
<% if current_user.admin? then %>
|
||||
<th>Cards</th>
|
||||
<% end %>
|
||||
<th>Certifications</th>
|
||||
<th>Active?</th>
|
||||
<th>Waiver?</th>
|
||||
<% if current_user.admin? then %>
|
||||
<th>Orientation?</th>
|
||||
<% end %>
|
||||
<th>Admin?</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
@@ -20,16 +24,22 @@
|
||||
<% if !@users.blank? %>
|
||||
<% @users.each do |user| %>
|
||||
<tr>
|
||||
<td><%= user.name %></td>
|
||||
<td><%= link_to user.name, user %></td>
|
||||
<td><%= user.email %></td>
|
||||
<% if current_user.admin? then %><td>
|
||||
<% user.cards.each do |c| %>
|
||||
<%= link_to c.card_number, card_url(c) %><%= "," unless c == user.cards.last %>
|
||||
<% end %>
|
||||
</td><% end %>
|
||||
<td><%= if user.active? then "Active" end %></td>
|
||||
<td><%= if user.waiver.blank? then "Not Signed" else "Signed" end %></td>
|
||||
<td><%= if user.admin? then "Admin" end %></td>
|
||||
<td><% user.certifications.each do |c| %>
|
||||
<%= link_to c.name, c %><%= "," unless c == user.certifications.last %>
|
||||
<% end %></td>
|
||||
<td><%= if user.active? then raw("✓") end %></td>
|
||||
<td><%= unless user.waiver.blank? then raw("<span class='hoverinfo' title='"+user.waiver.strftime("%B %d %Y")+"'>✓</span>") end %></td>
|
||||
<% if current_user.admin? then %><td>
|
||||
<%= unless user.orientation.blank? then raw("<span class='hoverinfo' title='"+user.orientation.strftime("%B %d %Y")+"'>✓</span>") end %>
|
||||
</td><% end %>
|
||||
<td><%= if user.admin? then raw("✓") end %></td>
|
||||
<td><%= link_to 'Edit', edit_user_path(user) if can? :update, user %></td>
|
||||
<td><%= 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 %></td>
|
||||
</tr>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<b>Certifications:</b>
|
||||
<ul>
|
||||
<% @user.certifications.each do |certification| %>
|
||||
<li>certification.name</li>
|
||||
<li><%= link_to certification.name, certification %></li>
|
||||
<% end %>
|
||||
<% if @user.certifications.blank? %><li>n/a</li><% end %>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user