Class: UsersController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary collapse

Methods included from SessionsHelper

#sessions_current_user, #sessions_current_user=, #sessions_sign_in, #sessions_sign_out, #sessions_signed_in?

Instance Method Details

#createObject

POST /users



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

def create
  @user = User.new(user_params)
  if @user.save
     @user
    flash[:success] = 'Thanks for signing up and welcome to TaxonWorks!'
    redirect_to root_path
  else
    @page_title = 'Create account'
    render 'new'
  end
end

#destroyObject

DELETE /users/:id



53
54
55
56
57
# File 'app/controllers/users_controller.rb', line 53

def destroy
  User.find(params[:id]).destroy
  flash[:success] = "Your account has been deleted."
  redirect_to root_url
end

#editObject

GET /users/:id/edit



22
23
24
25
# File 'app/controllers/users_controller.rb', line 22

def edit
  @user = User.find(params[:id])
  @page_title = "Edit user #{@user.id}"
end

#indexObject

GET /users



4
5
6
7
# File 'app/controllers/users_controller.rb', line 4

def index
  @users = User.all
  @page_title = 'Users'
end

#newObject

GET /signup



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

def new
  @user = User.new
  @page_title = 'Create account'
end

#showObject

GET /users/:id



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

def show
  @user = User.find(params[:id])
  @page_title = "User #{@user.id}"
end

#updateObject

PATCH or PUT /users/:id



41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/users_controller.rb', line 41

def update
  @user = User.find(params[:id])
  if @user.update_attributes(user_params)
    flash[:success] = 'Changes to your account information have been saved.'
    redirect_to @user
  else
    @page_title = "Edit user #{@user.id}"
    render 'edit'
  end
end