Sha256: 91c2abb4a49f1e561cf84cd64c90cace55c60db89e6846bbb1269bc0a51c4708

Contents?: true

Size: 1.95 KB

Versions: 6

Compression:

Stored size: 1.95 KB

Contents

class Admin::UsersController < Admin::BaseController
  authorise :roles => :admin
  sortable_attributes :name, :email, :role 

  # GET /users
  # GET /users.xml
  def index
    @users = User.paginate :page => params[:page], :per_page => 20, :order => sort_order

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @users }
    end
  end

  # GET /users/new
  # GET /users/new.xml
  def new
    @user = User.new
    render :action => 'show'
  end

  # GET /users/1/edit
  def show
    @user = User.find(params[:id])
  end

  # POST /users
  # POST /users.xml
  def create    
    @user = User.new(params[:user])
    # Because mass assignment is protected
    @user.role = params[:user][:role]
    respond_to do |format|
      if @user.save
        @user.confirm_email!
        flash[:notice] = 'User was successfully created.'
        format.html { redirect_to(admin_users_url) }
        format.xml  { render :xml => @user, :status => :created, :location => @user }
      else
        format.html { render :action => "show" }
        format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /users/1
  # PUT /users/1.xml
  def update  
    @user = User.find(params[:id])
    # Because mass assignment is protected
    @user.role = params[:user][:role]
    respond_to do |format|
      if @user.update_attributes(params[:user])
        flash[:notice] = 'User was successfully updated.'
        format.html { redirect_to(admin_users_url) }
        format.xml  { head :ok }
      else
        format.html { render :action => "show" }
        format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /users/1
  # DELETE /users/1.xml
  def destroy
    @user = User.find(params[:id])
    @user.destroy
    
    respond_to do |format|
      format.html { redirect_to(admin_users_url) }
      format.xml  { head :ok }
    end
  end
  
end       

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
beef-admin_area-0.1.1 app/controllers/admin/users_controller.rb
beef-admin_area-0.1.2 app/controllers/admin/users_controller.rb
beef-admin_area-0.1.3 app/controllers/admin/users_controller.rb
beef-admin_area-0.1.4 app/controllers/admin/users_controller.rb
beef-admin_area-0.1.6 app/controllers/admin/users_controller.rb
beef-admin_area-0.1.7 app/controllers/admin/users_controller.rb