QutBioacousticsResearchGroup/bioacoustic-workbench

View on GitHub
app/controllers/sites_controller.rb

Summary

Maintainability
A
1 hr
Test Coverage
class SitesController < ApplicationController
  # GET /sites
  # GET /sites.json
  def index
    @sites = Site.all

    respond_to do |format|
      format.json { render json: @sites }
    end
  end

  # GET /sites/1
  # GET /sites/1.json
  def show
    @site = Site.find(params[:id])

    respond_to do |format|
      format.json { render json: @site }
    end
  end

  # GET /sites/new
  # GET /sites/new.json
  def new
    @site = Site.new

    respond_to do |format|
      format.json { render json: @site }
    end
  end

  # GET /sites/1/edit
  #def edit
  #  @site = Site.find(params[:id])
  #end

  # POST /sites
  # POST /sites.json
  def create
    @site = Site.new(params[:site])

    respond_to do |format|
      if @site.save
        format.json { render json: @site, status: :created, location: @site }
      else
        format.json { render json: @site.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /sites/1
  # PUT /sites/1.json
  def update
    @site = Site.find(params[:id])

    respond_to do |format|
      if @site.update_attributes(params[:site])
        format.json { head :no_content }
      else
        format.json { render json: @site.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /sites/1
  # DELETE /sites/1.json
  def destroy
    @site = Site.find(params[:id])
    @site.destroy

    add_archived_at_header(@site)

    respond_to do |format|
      format.json { no_content_as_json }
    end
  end
end