organizations_controller.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. class OrganizationsController < ApplicationController
  2. before_filter :authentication_check
  3. # GET /organizations
  4. def index
  5. @organizations = Organization.all
  6. render :json => @organizations
  7. end
  8. # GET /organizations/1
  9. def show
  10. @organization = Organization.find(params[:id])
  11. render :json => @organization
  12. end
  13. # POST /organizations
  14. def create
  15. @organization = Organization.new(params[:organization])
  16. @organization.created_by_id = current_user.id
  17. if @organization.save
  18. render :json => @organization, :status => :created
  19. else
  20. render :json => @organization.errors, :status => :unprocessable_entity
  21. end
  22. end
  23. # PUT /organizations/1
  24. def update
  25. @organization = Organization.find(params[:id])
  26. if @organization.update_attributes(params[:organization])
  27. render :json => @organization, :status => :ok
  28. else
  29. render :json => @organization.errors, :status => :unprocessable_entity
  30. end
  31. end
  32. # DELETE /organizations/1
  33. def destroy
  34. @organization = Organization.find(params[:id])
  35. @organization.destroy
  36. head :ok
  37. end
  38. end