Sha256: 2143e93422424ae12b4ca4051338187c9ec9755f564eacc78d3514b7d3e4ff8d

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

class Admin::UsersController < ApplicationController
  layout 'admin'

  admin_assistant_for User do |a|
    a.actions << :destroy
    
    a[:state].input = :us_state
    
    a.index do |index|
      index.columns :id, :username, :password, :first_name, :last_name
      index.right_column_links << lambda { |user|
        [ "New blog post",
          { :controller => '/admin/blog_posts', :action => 'new',
            :blog_post => {:user_id => user.id} } ]
      }
      index.search.default_search_matches_on(
        :username, "users.first_name || ' ' || users.last_name"
      )
    end
    
    a.form do |form|
      form.columns :username, :password, :admin_level, :birthday, :state,
                   :force_blog_posts_to_textile, :first_name, :last_name
      form[:admin_level].input = :select
      form[:admin_level].select_choices = %w(normal admin superuser)
      form[:admin_level].select_options = {:include_blank => false}
      form[:birthday].date_select_options =
          {:start_year => Time.now.year-100, :end_year => Time.now.year}
      form[:force_blog_posts_to_textile].input = :select
      form[:force_blog_posts_to_textile].select_options =
          {:include_blank => true}
    end
  end
  
  protected
  
  # Run before a user is created
  def before_create(user)
    user.reset_password
  end
  
  # If 'reset_password' is checked, reset the password
  def before_update(user)
    if params[:reset_password]
      user.reset_password
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
admin_assistant-2.1.0 rails_3_0/app/controllers/admin/users_controller.rb
admin_assistant-2.0.1 rails_3_test/app/controllers/admin/users_controller.rb