# -*- encoding : utf-8 -*-

class Admin::OpenRangesController < ApplicationController
  layout "admin"
  before_action :auth_admin

  before_action :admin_space
  
  def admin_space
    @admin_space = "default"
  end
  
  def index
    @open_ranges = OpenRange.order(:name).all

  end

  def show
    @open_range = OpenRange.find(params[:id])

  end

  def new
    @open_range = OpenRange.new
  
  end

  def edit
    @open_range = OpenRange.find(params[:id])
    
  end

  def create
    @open_range = OpenRange.new(params.require(:open_range).permit!)

    if @open_range.save
      
    else
      render action: "new"
 
    end

  end


  def update
    @open_range = OpenRange.find(params[:id])


    if @open_range.update_attributes(params.require(:open_range).permit!)
      
    else
     render action: "edit" 
      
    end
      
  end


  def destroy
    @open_range = OpenRange.find(params[:id])
    @open_range.destroy
    
  end
end
