Sha256: 62fb2e0b07a61debd7edd257819f975ac1bec97fe91f2da9ee691e1b65c723b3

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

class AreasController < ApplicationController
  include Applicat::Mvc::Controller::Resource
  
  load_and_authorize_resource
  
  rescue_from ActiveRecord::RecordNotFound, with: :not_found
  
  respond_to :html, :js, :json
  
  def index
    @areas = Area.roots
      
    respond_to do |format|
      format.html
      format.json { render json: @areas.tokens(params[:q]) }
    end
  end
  
  def show
    @area = Area.find(params[:id])
    @areas = @area.children
    @projects = @area.projects
  end
  
  def new
    @area = Area.new(params[:area])
  end
  
  def create
    @area = Area.new(params[:area])
    
    if @area.save
      redirect_to @area, notice: t('general.form.successfully_created')
    else
      render :new
    end
  end
  
  def edit
    @area = Area.find(params[:id])
  end
  
  def update
    @area = Area.find(params[:id])
    
    if @area.update_attributes(params[:area])
      redirect_to @area, notice: t('general.form.successfully_updated')
    else
      render :edit
    end
  end

  def destroy
    @area = Area.find(params[:id])
    @area.destroy
    redirect_to areas_url, notice: t('general.form.destroyed')
  end
  
  def resource
    @area
  end
  
  private
  
  def not_found
    redirect_to areas_path, notice: t('areas.exceptions.not_found')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
voluntary-0.1.0 app/controllers/areas_controller.rb
voluntary-0.1.0.rc4 app/controllers/areas_controller.rb
voluntary-0.1.0.rc3 app/controllers/areas_controller.rb