Class: Spree::Api::UsersController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::UsersController
- Defined in:
- app/controllers/spree/api/users_controller.rb
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/spree/api/users_controller.rb', line 28 def create :create, user_class @user = user_class.new(permitted_user_params) if @user.save respond_with(@user, status: 201, default_template: :show) else invalid_resource!(@user) end end |
#destroy ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/spree/api/users_controller.rb', line 50 def destroy :destroy, @user destroy_result = if @user.respond_to?(:discard) @user.discard else @user.destroy end if destroy_result respond_with(@user, status: 204) else invalid_resource!(@user) end rescue ActiveRecord::DeleteRestrictionError render "spree/api/errors/delete_restriction", status: 422 end |
#index ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/spree/api/users_controller.rb', line 6 def index user_scope = user_class.accessible_by(current_ability, :show) if params[:ids] ids = params[:ids].split(",").flatten @users = user_scope.where(id: ids) else @users = user_scope.ransack(params[:q]).result end @users = paginate(@users.distinct) respond_with(@users) end |
#new ⇒ Object
23 24 25 26 |
# File 'app/controllers/spree/api/users_controller.rb', line 23 def new :new, user_class respond_with(user_class.new) end |
#show ⇒ Object
19 20 21 |
# File 'app/controllers/spree/api/users_controller.rb', line 19 def show respond_with(@user) end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/spree/api/users_controller.rb', line 40 def update :update, @user if @user.update(permitted_user_params) respond_with(@user, status: 200, default_template: :show) else invalid_resource!(@user) end end |