diff --git a/app/assets/javascripts/certifications.js.coffee b/app/assets/javascripts/certifications.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/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/certifications.css.scss b/app/assets/stylesheets/certifications.css.scss new file mode 100644 index 0000000..2e35715 --- /dev/null +++ b/app/assets/stylesheets/certifications.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Certifications controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/certifications_controller.rb b/app/controllers/certifications_controller.rb new file mode 100644 index 0000000..5cda4ad --- /dev/null +++ b/app/controllers/certifications_controller.rb @@ -0,0 +1,77 @@ +class CertificationsController < ApplicationController + load_and_authorize_resource :certification + load_and_authorize_resource :user, :through => :certification + before_filter :authenticate_user! + + # GET /certifications + # GET /certifications.json + def index + @certifications = @certifications.sort_by(&:name) + + respond_to do |format| + format.html # index.html.erb + format.json { render :json => @certifications } + end + end + + # GET /certifications/1 + # GET /certifications/1.json + def show + respond_to do |format| + format.html # show.html.erb + format.json { render :json => @certification } + end + end + + # GET /certifications/new + # GET /certifications/new.json + def new + respond_to do |format| + format.html # new.html.erb + format.json { render :json => @certification } + end + end + + # GET /certifications/1/edit + def edit + end + + # POST /certifications + # POST /certifications.json + def create + respond_to do |format| + if @certification.save + format.html { redirect_to Certification, :notice => 'Certification was successfully created.' } + format.json { render :json => @certification, :status => :created, :location => @certification } + else + format.html { render :action => "new" } + format.json { render :json => @certification.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /certifications/1 + # PUT /certifications/1.json + def update + respond_to do |format| + if @certification.update_attributes(params[:certification]) + format.html { redirect_to Certification, :notice => 'Certification was successfully updated.' } + format.json { head :no_content } + else + format.html { render :action => "edit" } + format.json { render :json => @certification.errors, :status => :unprocessable_entity } + end + end + end + + # DELETE /certifications/1 + # DELETE /certifications/1.json + def destroy + @certification.destroy + + respond_to do |format| + format.html { redirect_to certifications_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/certifications_helper.rb b/app/helpers/certifications_helper.rb new file mode 100644 index 0000000..906dc2e --- /dev/null +++ b/app/helpers/certifications_helper.rb @@ -0,0 +1,2 @@ +module CertificationsHelper +end diff --git a/app/models/ability.rb b/app/models/ability.rb index 975bfa9..3201c8e 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -5,10 +5,14 @@ class Ability if !user.nil? if user.admin? can :manage, :all - else - can :read, User - can :read, Card, :user_id => user.id end + if user.instructor? + can :manage, Certification + end + + can :read, User + can :read, Certification + can :read, Card, :user_id => user.id end # Define abilities for the passed in user here. For example: # diff --git a/app/models/certification.rb b/app/models/certification.rb new file mode 100644 index 0000000..665688d --- /dev/null +++ b/app/models/certification.rb @@ -0,0 +1,4 @@ +class Certification < ActiveRecord::Base + attr_accessible :description, :name + has_many :users, :through => :certifications_users +end diff --git a/app/models/user.rb b/app/models/user.rb index 9c34875..a64b895 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,7 +6,8 @@ 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, :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 has_many :cards + has_many :certifications, :through => :certifications_users end diff --git a/app/views/certifications/_form.html.erb b/app/views/certifications/_form.html.erb new file mode 100644 index 0000000..0eb73e4 --- /dev/null +++ b/app/views/certifications/_form.html.erb @@ -0,0 +1,29 @@ +<%= form_for(@certification) do |f| %> + <% if @certification.errors.any? %> +
+ Name: + <%= @certification.name %> +
+ ++ Description: + <%= simple_format @certification.description %> +
+ +Certified Users: +