Class: LesliShield::UsersController
- Inherits:
-
ApplicationController
- Object
- Lesli::ApplicationLesliController
- ApplicationController
- LesliShield::UsersController
- Defined in:
- app/controllers/lesli_shield/users_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /users.
-
#destroy ⇒ Object
DELETE /users/1.
-
#edit ⇒ Object
GET /users/1/edit.
-
#index ⇒ Object
GET /users.
-
#new ⇒ Object
GET /users/new.
-
#show ⇒ Object
GET /users/1.
-
#update ⇒ Object
PATCH/PUT /users/1.
Instance Method Details
#create ⇒ Object
POST /users
32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/lesli_shield/users_controller.rb', line 32 def create @user = User.new(user_params) if @user.save redirect_to @user, notice: "User was successfully created." else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
DELETE /users/1
64 65 66 67 |
# File 'app/controllers/lesli_shield/users_controller.rb', line 64 def destroy @user.destroy! redirect_to users_path, notice: "User was successfully destroyed.", status: :see_other end |
#edit ⇒ Object
GET /users/1/edit
28 29 |
# File 'app/controllers/lesli_shield/users_controller.rb', line 28 def edit end |
#index ⇒ Object
GET /users
6 7 8 |
# File 'app/controllers/lesli_shield/users_controller.rb', line 6 def index @users = respond_as_pagination(Lesli::UserService.new(current_user, query).index(params)) end |
#new ⇒ Object
GET /users/new
23 24 25 |
# File 'app/controllers/lesli_shield/users_controller.rb', line 23 def new @user = User.new end |
#show ⇒ Object
GET /users/1
11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/lesli_shield/users_controller.rb', line 11 def show @activities = @user.result.activities.order(id: :desc).map { |a| { id: a[:id], title: a[:title].titleize, description: a[:description], date: Date2.new(a[:created_at]).date_words }} @sessions = @user.result.sessions @user = @user.show end |
#update ⇒ Object
PATCH/PUT /users/1
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/lesli_shield/users_controller.rb', line 43 def update # check if the user trully exists return respond_with_not_found unless @user.found? # update the user information @user.update(user_params) # check saved if @user.successful? success("User updated successfully!") respond_to do |format| format.turbo_stream format.html { redirect_to @user } end else respond_with_error(@user.errors) end end |