2012-04-10 14:06:46 +00:00
|
|
|
class RolesController < ApplicationController
|
|
|
|
before_filter :authentication_check
|
|
|
|
|
|
|
|
# GET /roles
|
|
|
|
def index
|
|
|
|
@roles = Role.all
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @roles
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /roles/1
|
|
|
|
def show
|
|
|
|
@role = Role.find(params[:id])
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @role
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /roles/new
|
|
|
|
def new
|
|
|
|
@role = Role.new
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
render :json => @role
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# POST /roles
|
|
|
|
def create
|
|
|
|
@role = Role.new(params[:role])
|
|
|
|
@role.created_by_id = current_user.id
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
if @role.save
|
|
|
|
render :json => @role, :status => :created
|
|
|
|
else
|
|
|
|
render :json => @role.errors, :status => :unprocessable_entity
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /roles/1
|
|
|
|
def update
|
|
|
|
@role = Role.find(params[:id])
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
if @role.update_attributes(params[:role])
|
|
|
|
render :json => @role, :status => :ok
|
|
|
|
else
|
|
|
|
render :json => @role.errors, :status => :unprocessable_entity
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /roles/1
|
|
|
|
def destroy
|
|
|
|
@role = Role.find(params[:id])
|
|
|
|
@role.destroy
|
|
|
|
|
2012-04-12 11:27:01 +00:00
|
|
|
head :ok
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|