Class: Guts::UsersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Guts::UsersController
- Includes:
- ControllerPermissionConcern
- Defined in:
- app/controllers/guts/users_controller.rb
Overview
Users controller
Instance Method Summary collapse
-
#create ⇒ Object
Creates a user through post.
-
#destroy ⇒ Object
Destroys a single user.
-
#edit ⇒ Object
Editing of a user.
-
#index ⇒ Object
Displays a list of users.
-
#new ⇒ Object
Creation of a new user.
-
#show ⇒ Object
Show details about a single user.
-
#switch_user ⇒ Object
Allows switching of users by passing ‘user_id` in params.
-
#update ⇒ Object
Updates a user through patch.
Methods inherited from ApplicationController
Methods included from MultisiteConcern
#current_site, #with_current_site
Instance Method Details
#create ⇒ Object
Note:
Redirects to #index if successfull or re-renders #new if not
Creates a user through post
37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/guts/users_controller.rb', line 37 def create @user = User.new user_params if @user.save flash[:notice] = 'User was successfully created.' redirect_to edit_user_path(@user) else render :new end end |
#destroy ⇒ Object
Note:
Redirects to #index on success
Destroys a single user
61 62 63 64 65 66 |
# File 'app/controllers/guts/users_controller.rb', line 61 def destroy @user.destroy flash[:notice] = 'User was successfully destroyed.' redirect_to users_url end |
#edit ⇒ Object
Editing of a user
32 33 |
# File 'app/controllers/guts/users_controller.rb', line 32 def edit end |
#index ⇒ Object
Note:
Filterable by group by passing ‘group` param
Displays a list of users
13 14 15 16 17 18 19 20 |
# File 'app/controllers/guts/users_controller.rb', line 13 def index if params[:group] @group = Group.find params[:group] @users = User.in_group(@group) else @users = User.all end end |
#new ⇒ Object
Creation of a new user
27 28 29 |
# File 'app/controllers/guts/users_controller.rb', line 27 def new @user = User.new end |
#show ⇒ Object
Show details about a single user
23 24 |
# File 'app/controllers/guts/users_controller.rb', line 23 def show end |
#switch_user ⇒ Object
Allows switching of users by passing ‘user_id` in params
70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/guts/users_controller.rb', line 70 def switch_user if request.post? user = User.find(params[:user_id]) log_in user flash.now[:notice] = "You are now logged in as #{user.name}." end @users = User.all end |
#update ⇒ Object
Note:
Redirects to #index if successfull or re-renders #edit if not
Updates a user through patch
50 51 52 53 54 55 56 57 |
# File 'app/controllers/guts/users_controller.rb', line 50 def update if @user.update(user_params) flash[:notice] = 'User was successfully updated.' redirect_to edit_user_path(@user) else render :edit end end |