2013-01-25 10:50:53 +00:00
|
|
|
class UserCertificationsController < ApplicationController
|
2013-01-25 13:01:02 +00:00
|
|
|
load_and_authorize_resource :user_certification
|
|
|
|
load_and_authorize_resource :user, :through => :user_certification
|
|
|
|
load_and_authorize_resource :certification, :through => :user_certification
|
|
|
|
before_filter :authenticate_user!
|
|
|
|
|
2013-01-25 13:52:19 +00:00
|
|
|
# Load users and certs based on current ability
|
|
|
|
before_filter :only => [:new, :edit, :create, :update] do
|
2013-05-03 07:16:02 +00:00
|
|
|
@users = User.where(:hidden => false).accessible_by(current_ability).sort_by(&:name)
|
2013-01-25 13:52:19 +00:00
|
|
|
@certifications = Certification.accessible_by(current_ability).sort_by(&:name)
|
|
|
|
end
|
2013-01-25 13:01:02 +00:00
|
|
|
|
2013-01-25 10:50:53 +00:00
|
|
|
# GET /user_certifications
|
|
|
|
# GET /user_certifications.json
|
|
|
|
def index
|
2013-01-25 18:11:39 +00:00
|
|
|
@grouped_user_certs = @user_certifications.group_by { |uc| uc.certification }
|
2013-01-25 10:50:53 +00:00
|
|
|
|
|
|
|
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
|
2013-01-25 13:52:19 +00:00
|
|
|
@created_by = User.find(@user_certification.created_by) unless @user_certification.created_by.blank?
|
|
|
|
@updated_by = User.find(@user_certification.updated_by) unless @user_certification.updated_by.blank?
|
|
|
|
|
2013-01-25 10:50:53 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # new.html.erb
|
|
|
|
format.json { render :json => @user_certification }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /user_certifications/1/edit
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /user_certifications
|
|
|
|
# POST /user_certifications.json
|
|
|
|
def create
|
2013-01-25 13:52:19 +00:00
|
|
|
#Log who created this
|
|
|
|
@user_certification.created_by = current_user.id
|
|
|
|
|
2013-01-25 10:50:53 +00:00
|
|
|
respond_to do |format|
|
|
|
|
if @user_certification.save
|
2013-01-25 13:01:02 +00:00
|
|
|
format.html { redirect_to UserCertification, :notice => 'User certification was successfully created.' }
|
2013-01-25 10:50:53 +00:00
|
|
|
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
|
2013-01-25 13:52:19 +00:00
|
|
|
#Log who updated this
|
|
|
|
@user_certification.updated_by = current_user.id
|
|
|
|
|
2013-01-25 10:50:53 +00:00
|
|
|
respond_to do |format|
|
|
|
|
if @user_certification.update_attributes(params[:user_certification])
|
2013-01-25 13:01:02 +00:00
|
|
|
format.html { redirect_to UserCertification, :notice => 'User certification was successfully updated.' }
|
2013-01-25 10:50:53 +00:00
|
|
|
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.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to user_certifications_url }
|
|
|
|
format.json { head :no_content }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|