Class: Grandstand::UsersController

Inherits:
MainController
  • Object
show all
Defined in:
app/controllers/grandstand/users_controller.rb

Instance Method Summary collapse

Methods inherited from MainController

#expand

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/grandstand/users_controller.rb', line 4

def create
  @user = Grandstand::User.new(params[:user])
  if @user.save
    flash[:success] = "#{@user.name} was successfully added"
    redirect_to grandstand_user_path(@user)
  else
    flash[:error] = 'There was a problem creating this user'
    render :new
  end
end

#deleteObject



15
16
17
# File 'app/controllers/grandstand/users_controller.rb', line 15

def delete
  return grandstand_not_found if @user.id == current_user.id
end

#destroyObject



19
20
21
22
23
24
# File 'app/controllers/grandstand/users_controller.rb', line 19

def destroy
  return grandstand_not_found if @user.id == current_user.id
  @user.destroy
  flash[:delete] = 'Your user has been deleted'
  redirect_to grandstand_users_path
end

#indexObject



26
27
28
# File 'app/controllers/grandstand/users_controller.rb', line 26

def index
  @users = Grandstand::User.all
end

#newObject



30
31
32
# File 'app/controllers/grandstand/users_controller.rb', line 30

def new
  @user = Grandstand::User.new
end

#updateObject



34
35
36
37
38
39
40
41
42
# File 'app/controllers/grandstand/users_controller.rb', line 34

def update
  if @user.update_attributes(params[:user])
    flash[:success] = "#{@user.name} was successfully saved"
    request.xhr? ? render(:json => {:status => :ok}) : redirect_to(grandstand_user_path(@user))
  else
    flash[:error] = 'There was a problem saving this user'
    render :edit
  end
end