Sha256: 098190974b0f3e47d528edd27b6d1dd13e9d3bbbc6511a3758bc8495bf28f600
Contents?: true
Size: 925 Bytes
Versions: 3
Compression:
Stored size: 925 Bytes
Contents
class UsersController < ApplicationController before_filter :authenticate_user! before_filter :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
3 entries across 3 versions & 1 rubygems