Sha256: b1f11c42916d28e379d474220789eba55776722cd724654625b64077c166cbc0

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

class Hq::UsersController < Hq::ApplicationController

  before_action :set_user, only: [:show, :edit, :update, :destroy, :toggle_is_active]
  add_breadcrumb I18n.t('activerecord.models.users'), :hq_users_path

  def index
    @search = User.order(id: :desc).search(params[:q])
    @users = @search.result(distinct: true).paginate(page: params[:page])
    respond_with(@users)
  end

  def show
    add_breadcrumb @user.name, hq_user_path(@user)
    respond_with(@user)
  end

  def new
    add_breadcrumb t('tooltips.new'), new_hq_user_path
    @user = User.new
    respond_with(@user)
  end

  def edit
    add_breadcrumb @user.name, hq_user_path(@user)
    add_breadcrumb t('tooltips.edit'), edit_hq_user_path
  end

  def create
    @user = User.new(user_params)
    @user.save
    respond_with(:hq, @user)
  end

  def update
    @user.update(user_params)
    respond_with(:hq, @user)
  end

  def destroy
    @user.destroy
    respond_with(:hq, @user, location: request.referer)
  end

  def toggle_is_active
    if @user.update( is_active: !@user.is_active )
      @user.is_active ?
          flash[:info] = t('flash.actions.toggle_is_active.active', resource_name: User.model_name.human) :
          flash[:info] = t('flash.actions.toggle_is_active.passive', resource_name: User.model_name.human)
    else
      flash[:danger] = t('flash.messages.error_occurred')
    end
    respond_with(:hq, @user, location: request.referer)
  end

  private

  def set_user
    @user = User.find(params[:id])
  end

  def user_params
    params.require(:user).permit(:email, :name, :surname, :time_zone)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cybele-1.9.2 templates/app/controllers/hq/users_controller.rb
cybele-1.9.1 templates/app/controllers/hq/users_controller.rb
cybele-1.9.0 templates/app/controllers/hq/users_controller.rb