class Admin::CountriesController < ApplicationController

  before_filter :superadmin_login_required

  def create
    @country = Country.new(permitted_params)

    if @country.save
      redirect_to admin_countries_path, notice: I18n.t('successfully_updated')
    else
      render action: "new"
    end
  end

  def update
    @country = Country.find(params[:id].to_i)
    if @country.update_attributes(permitted_params)
      redirect_to admin_countries_path, notice: I18n.t('successfully_updated')
    else
      render action: "edit"
    end
  end

  def destroy
    @country = Country.find(params[:id])
    @country.destroy
    # redirect_to admin_countries_path(), notice: I18n.t('deleted')
    @countries = Country.all
    render action: :index
  end

  def index
    @countries = Country.all
    render layout: nil
  end

  def edit
    @country = Country.find(params[:id])
    render layout: nil
  end

  def new
    @country = Country.new
    render layout: nil
  end

  def show
    @country = Country.find(params[:id])
  end

  private

  def permitted_params
    params.require(:country).permit(:name)
  end

end
