Class: Spree::AddressesController

Inherits:
StoreController show all
Defined in:
app/controllers/spree/addresses_controller.rb

Instance Method Summary collapse

Methods inherited from StoreController

#account_link, #api_tokens, #cart_link, #ensure_cart

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
# File 'app/controllers/spree/addresses_controller.rb', line 7

def create
  @address = try_spree_current_user.addresses.build(address_params)
  if create_service.call(user: try_spree_current_user, address_params: @address.attributes).success?
    flash[:notice] = I18n.t(:successfully_created, scope: :address_book)
    redirect_to spree.
  else
    render action: 'new', status: :unprocessable_entity
  end
end

#destroyObject



34
35
36
37
38
39
# File 'app/controllers/spree/addresses_controller.rb', line 34

def destroy
  @address.destroy

  flash[:notice] = Spree.t(:successfully_removed, scope: :address_book)
  redirect_to(request.env['HTTP_REFERER'] || addresses_path) unless request.xhr?
end

#editObject



17
18
19
# File 'app/controllers/spree/addresses_controller.rb', line 17

def edit
  session['spree_user_return_to'] = request.env['HTTP_REFERER']
end

#newObject



21
22
23
# File 'app/controllers/spree/addresses_controller.rb', line 21

def new
  @address = Spree::Address.new(country: current_store.default_country, user: try_spree_current_user)
end

#updateObject



25
26
27
28
29
30
31
32
# File 'app/controllers/spree/addresses_controller.rb', line 25

def update
  if update_service.call(address: @address, address_params: address_params).success?
    flash[:notice] = Spree.t(:successfully_updated, scope: :address_book)
    redirect_back_or_default(addresses_path)
  else
    render :edit, status: :unprocessable_entity
  end
end