Sha256: a95a460f5bc0d28d9948f930f549e82cb6ccfc8f617e08d9a8c7e371cfb7e707

Contents?: true

Size: 925 Bytes

Versions: 7

Compression:

Stored size: 925 Bytes

Contents

class UsersController < ApplicationController
  before_action :authenticate_user!
  before_action :admin_only, :except => :show

  def index
    @users = User.all
  end

  def show
    @user = User.find(params[:id])
    unless current_user.admin?
      unless @user == current_user
        redirect_to :back, :alert => "Access denied."
      end
    end
  end

  def update
    @user = User.find(params[:id])
    if @user.update_attributes(secure_params)
      redirect_to users_path, :notice => "User updated."
    else
      redirect_to users_path, :alert => "Unable to update user."
    end
  end

  def destroy
    user = User.find(params[:id])
    user.destroy
    redirect_to users_path, :notice => "User deleted."
  end

  private

  def admin_only
    unless current_user.admin?
      redirect_to :back, :alert => "Access denied."
    end
  end

  def secure_params
    params.require(:user).permit(:role)
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_apps_pages-0.6.6 lib/generators/pages/roles/templates/devise/users_controller.rb
rails_apps_pages-0.6.5 lib/generators/pages/roles/templates/devise/users_controller.rb
rails_apps_pages-0.6.4 lib/generators/pages/roles/templates/devise/users_controller.rb
rails_apps_pages-0.6.3 lib/generators/pages/roles/templates/devise/users_controller.rb
rails_apps_pages-0.6.2 lib/generators/pages/roles/templates/devise/users_controller.rb
rails_apps_pages-0.6.0 lib/generators/pages/roles/templates/devise/users_controller.rb
rails_apps_pages-0.5.16 lib/generators/pages/roles/templates/devise/users_controller.rb