Class: Admin::UsersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::UsersController
- Defined in:
- app/controllers/admin/users_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #export ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
48 49 50 51 |
# File 'app/controllers/admin/users_controller.rb', line 48 def create @user = SpudUser.create(user_params) respond_with @user, location: admin_users_path end |
#destroy ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/controllers/admin/users_controller.rb', line 74 def destroy @user.destroy respond_with @user, location: admin_users_path do |format| format.js{ render nothing: true, status: :ok } end end |
#edit ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/admin/users_controller.rb', line 53 def edit respond_with @user do |format| format.html{ if request.xhr? render 'edit', layout: false else render 'edit' end } end end |
#export ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/controllers/admin/users_controller.rb', line 26 def export users = SpudUser.all export_columns = %w[created_at first_name last_name email last_login_at] file_name = TbCore.site_name + ' Users Export.csv' send_data users.as_csv(export_columns), type: 'text/csv; charset=iso-8859-1; header=present', disposition: "attachment; filename=#{file_name}" end |
#index ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/controllers/admin/users_controller.rb', line 14 def index @spud_users = SpudUser.order(sortable_query).paginate(page: params[:page], per_page: 15) if params[:search] @spud_users = @spud_users.where_name_like(params[:search]) end respond_with @spud_users end |
#new ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/admin/users_controller.rb', line 35 def new @user = SpudUser.new respond_with @user do |format| format.html{ if request.xhr? render 'new', layout: false else render 'new' end } end end |
#show ⇒ Object
22 23 24 |
# File 'app/controllers/admin/users_controller.rb', line 22 def show respond_with @user end |
#update ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/controllers/admin/users_controller.rb', line 65 def update if @user.update(user_params) if @user == current_user && user_params[:password].present? SpudUserSession.create(@user) end end respond_with @user, location: admin_user_path(@user), status: 200 end |