Class: Manage::UsersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Manage::UsersController
- Defined in:
- app/controllers/binda/manage/users_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/binda/manage/users_controller.rb', line 22 def create @user = User.new( user_params ) respond_to do |format| if @user.save format.html { redirect_to manage_user_path( @user.id ), notice: 'User was successfully created.' } format.xml { head :ok } format.json { render :show, status: :created, location: @user } else format.html { redirect_to new_manage_user_path, flash: { alert: @user.errors } } format.xml { head :bad_request } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/binda/manage/users_controller.rb', line 55 def destroy if current_user.email == @user.email redirect_to manage_users_url, flash: { alert: 'Sorry, you cannot delete your own account.' } elsif @user.is_superadmin && !current_user.is_superadmin redirect_to manage_users_url, flash: { alert: 'Sorry, you cannot delete an administrator.' } else @user.destroy respond_to do |format| format.html { redirect_to manage_users_url, notice: 'User was successfully destroyed.' } format.xml { head :ok } format.json { head :no_content } end end end |
#edit ⇒ Object
19 20 |
# File 'app/controllers/binda/manage/users_controller.rb', line 19 def edit end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/binda/manage/users_controller.rb', line 7 def index @users = User.all end |
#new ⇒ Object
15 16 17 |
# File 'app/controllers/binda/manage/users_controller.rb', line 15 def new @user = User.new end |
#show ⇒ Object
11 12 13 |
# File 'app/controllers/binda/manage/users_controller.rb', line 11 def show redirect_to action: :edit end |
#update ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/binda/manage/users_controller.rb', line 38 def update # Check if the user to be updated is superadmin and the user which is updating is superadmin check_if_superadmin respond_to do |format| if @user.update(user_params) format.html { redirect_to manage_user_path( @user.id ), notice: 'User was successfully updated.' } format.xml { head :ok } format.json { render :show, status: :ok, location: @user } else format.html { redirect_to edit_manage_user_path( @user.id ), flash: { alert: @user.errors } } format.xml { head :bad_request } format.json { render json: @user.errors, status: :unprocessable_entity } end end end |