class AdminsController

Public Instance Methods

create() click to toggle source

Create a new Admin

# File app/controllers/admins_controller.rb, line 40
def create
  # Default attributes: role = TA or role = STUDENT
  # params[:user] is a hash of values passed to the controller
  # by the HTML form with the help of ActiveView::Helper::
  @user = Admin.new(params[:user])
  # Return unless the save is successful; save inherted from
  # active records--creates a new record if the model is new, otherwise
  # updates the existing record
  if @user.save
    flash[:success] = I18n.t('admins.create.success',
      :user_name => @user.user_name)

    redirect_to :action => 'index'
  else
    flash[:error] = I18n.t('admins.create.error')
    render 'new'
  end
end
edit() click to toggle source
# File app/controllers/admins_controller.rb, line 17
def edit
  @user = Admin.find_by_id(params[:id])
end
index() click to toggle source
# File app/controllers/admins_controller.rb, line 5
def index
end
new() click to toggle source
# File app/controllers/admins_controller.rb, line 21
def new
  @user = Admin.new(params[:user])
end
populate() click to toggle source
# File app/controllers/admins_controller.rb, line 8
def populate
  admins_data = Admin.all(:order => 'user_name')
  # construct_table_rows defined in UsersHelper
  @admins = construct_table_rows(admins_data)
  respond_to do |format|
    format.json { render :json => @admins }
  end
end
update() click to toggle source
# File app/controllers/admins_controller.rb, line 25
def update
  @user = Admin.find(params[:id])
  attrs = params[:user]
  # update_attributes supplied by ActiveRecords
  if @user.update_attributes(attrs).nil?
    flash[:error] = I18n.t('admins.update.error')
    render :edit
  else
    flash[:success] = I18n.t('admins.update.success',
      :user_name => @user.user_name)
    redirect_to :action => 'index'
  end
end