Class: Dunlop::UsersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ApplicationController
- Dunlop::UsersController
- Defined in:
- app/controllers/dunlop/users_controller.rb
Instance Method Summary collapse
- #become_user ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #edit_profile ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #permissions_table ⇒ Object
- #profile ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #update_profile ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#become_user ⇒ Object
67 68 69 70 71 |
# File 'app/controllers/dunlop/users_controller.rb', line 67 def become_user @user = User.find(params[:id]) sign_in @user, bypass_sign_in: true respond_with(@user, location: user_path) end |
#create ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/dunlop/users_controller.rb', line 34 def create @user = User.new user_params :create, @user if @user.save redirect_to dunlop.users_path else render action: :edit end end |
#destroy ⇒ Object
73 74 75 76 77 |
# File 'app/controllers/dunlop/users_controller.rb', line 73 def destroy :destroy, @user @user.destroy redirect_to dunlop.users_path end |
#edit ⇒ Object
48 49 50 |
# File 'app/controllers/dunlop/users_controller.rb', line 48 def edit :update, @user end |
#edit_profile ⇒ Object
11 12 |
# File 'app/controllers/dunlop/users_controller.rb', line 11 def edit_profile end |
#index ⇒ Object
24 25 26 27 |
# File 'app/controllers/dunlop/users_controller.rb', line 24 def index :index, User @users = User.active.page(params[:page]) end |
#new ⇒ Object
29 30 31 32 |
# File 'app/controllers/dunlop/users_controller.rb', line 29 def new @user = User.new :create, @user end |
#permissions_table ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/dunlop/users_controller.rb', line 79 def :permissions_table, User @table = Hash.new{|h,k| h[k] = Hash.new{|h2, k2| h2[k2] = []} } @users = User.active @users.each do |user| user.role_names.each do |role| if match = role.match(/(^[a-z0-9]+)-class-(.*)/) role_class = match[2].safe_constantize if role_class.respond_to?(:model_name) role = role_class.model_name.human else role = role_class.try(:name) end @table[role][user] << match[1] else @table[role][user] << "check" end end end end |
#profile ⇒ Object
8 9 |
# File 'app/controllers/dunlop/users_controller.rb', line 8 def profile end |
#show ⇒ Object
44 45 46 |
# File 'app/controllers/dunlop/users_controller.rb', line 44 def show :show, @user end |
#update ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/dunlop/users_controller.rb', line 52 def update :update, @user if user_params[:password].blank? @user.update_without_password(user_params) else @user.update_attributes(user_params) end if @user.errors.present? render action: :edit else redirect_to dunlop.users_path end end |
#update_profile ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/dunlop/users_controller.rb', line 14 def update_profile user_params = params.require(:user).permit(:password, :confirmation_password) if @user.update_attributes(user_params) sign_in @user, bypass_sign_in: true redirect_to dunlop.profile_users_path else render action: :edit_profile end end |