Class: Spree::Api::AddressBooksController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#destroyObject



39
40
41
42
43
44
# File 'app/controllers/spree/api/address_books_controller.rb', line 39

def destroy
  authorize! :remove_from_address_book, address_book_user

  address_book_user.remove_from_address_book(params[:address_id])
  render :show, status: :ok
end

#showObject



9
10
11
12
13
# File 'app/controllers/spree/api/address_books_controller.rb', line 9

def show
  authorize! :show, address_book_user

  render :show, status: :ok
end

#updateArray

Update a user’s address book by adding an address to it or by updating the associated UserAddress (e.g. making it the default).

Parameters:

  • user_id (String)

    the user id of the address book we’re updating.

  • address_book (Hash)

    any key-values permitted by permitted_address_book_attributes

Returns:

  • (Array)

    All of the user’s addresses, since the resource here is the address book and since we may have mutated other UserAddresses (e.g. changed the ‘default’ flag). The user’s default address will be flagged with default=true and the target address from this update will be flagged with update_target=true.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/spree/api/address_books_controller.rb', line 26

def update
  authorize! :save_in_address_book, address_book_user

  address_params = address_book_params
  default_flag = address_params.delete(:default)
  @address = address_book_user.save_in_address_book(address_params, default_flag)
  if @address.valid?
    render :show, status: :ok
  else
    invalid_resource!(@address)
  end
end