Sha256: b8b1e0d3103e7fbb6c890f5b6f17d9d0baf0060e387b6755c80e8e858c6f921e

Contents?: true

Size: 1.35 KB

Versions: 26

Compression:

Stored size: 1.35 KB

Contents

class Admin::UsersController < AdminController
  before_action :set_user, only: [:edit, :update, :destroy]

  def index
    respond_to do |format|
      format.html
      format.json do
        @users = User.order("created_at DESC").paginate page: params[:page], per_page: 10
        @count = User.count
      end
    end
  end

  def show
    respond_to do |format|
      format.html{ render }
      format.json{ set_user }
    end
  end

  def edit
    return if @user.confirmed?
    connection = Connection.for_obj(@user).last
    return if connection.nil?
    emit @user, :confirming, for: connection.token
  end

  def update
    if @user.update user_params
      if @user.confirmed? && connection = Connection.for_obj(@user).last
        emit @user, :confirmed, for: connection.token
        connection.destroy
      end
      render json: {success: true, status: 200, flash: {success: 'User updated!'}}
    else
      render json: {success: false, status: 400, errors: @user.errors}
    end
  end

  def destroy
    @user.destroy
    redirect_to :back, notice: "User was successfully destroyed."
  end

  private

    def set_user
      @user = if params[:id].present?
        User.find params[:id]
      else
        User.new
      end
    end

    def user_params
      params.require(:user).permit :email, :username, :password, :password_confirmation, :confirmed
    end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
loco-rails-3.0.3 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.5.3 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.5.2 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-3.0.2 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-3.0.1 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.5.1 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.5.0 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.4.0 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.3.0 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-3.0.0 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.2.2 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.2.1 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.2.0 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.1.0 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-2.0.0 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-1.5.2 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-1.5.1 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-1.5.0 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-1.4.0 test/dummy/app/controllers/admin/users_controller.rb
loco-rails-1.3.3 test/dummy/app/controllers/admin/users_controller.rb