Class: UsersController

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

Instance Method Summary collapse

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/users_controller.rb', line 22

def create
  @user = User.new(params[:user])
  if @user.save
    flash[:notice] = t :registration_successful_flash
    redirect_to root_path
  else
    render :action => 'new'
  end
end

#editObject



32
33
34
35
36
37
38
# File 'app/controllers/users_controller.rb', line 32

def edit
  @user = get_user_from_params(params)
  unless @user.can_be_modified_by(current_user)
    flash[:notice] = t(:access_denied_flash)
    @user.nil? ? redirect_to(root_path) : redirect_to("/users/#{@user.username}/edit")
  end
end

#indexObject



10
11
12
# File 'app/controllers/users_controller.rb', line 10

def index
  @users = User.paginate :page => params[:page]
end

#newObject



18
19
20
# File 'app/controllers/users_controller.rb', line 18

def new
  @user = User.new
end

#showObject



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

def show
  @user = get_user_from_params(params)
end

#updateObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/users_controller.rb', line 40

def update
  # dont you params here, should know the username
  @user = User.find(params['id'])
  if @user.can_be_modified_by(current_user)
    if @user.update_attributes(params['user'])
      flash[:notice] = t(:profil_change_success_flash)
      redirect_to root_path
    else
      render :action => 'edit'
    end
  else
    @user = current_user
    flash[:notice] = t(:access_denied_flash)
    render :action => 'edit'
  end
end