Class: Spree::Api::UsersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/users_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#map_nested_attributes_keys, #set_jsonp_format

Methods included from ControllerSetup

included

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
# File 'app/controllers/spree/api/users_controller.rb', line 19

def create
  authorize! :create, Spree.user_class
  @user = Spree.user_class.new(params[:user])
  if @user.save
    respond_with(@user, :status => 201, :default_template => :show)
  else
    invalid_resource!(@user)
  end
end

#destroyObject



38
39
40
41
42
# File 'app/controllers/spree/api/users_controller.rb', line 38

def destroy
  authorize! :destroy, user
  user.destroy
  respond_with(user, :status => 204)
end

#indexObject



6
7
8
9
# File 'app/controllers/spree/api/users_controller.rb', line 6

def index
  @users = Spree.user_class.accessible_by(current_ability,:read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
  respond_with(@users)
end

#newObject



16
17
# File 'app/controllers/spree/api/users_controller.rb', line 16

def new
end

#showObject



11
12
13
14
# File 'app/controllers/spree/api/users_controller.rb', line 11

def show
  authorize! :show, user
  respond_with(user)
end

#updateObject



29
30
31
32
33
34
35
36
# File 'app/controllers/spree/api/users_controller.rb', line 29

def update
  authorize! :update, user
  if user.update_attributes(params[:user])
    respond_with(user, :status => 200, :default_template => :show)
  else
    invalid_resource!(user)
  end
end