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