Class: Spree::Admin::StoresController

Inherits:
BaseController
  • Object
show all
Includes:
Translatable
Defined in:
app/controllers/spree/admin/stores_controller.rb

Instance Method Summary collapse

Methods included from Translatable

#edit_translations

Instance Method Details

#create ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/spree/admin/stores_controller.rb', line 15

def create
  @store = stores_scope.new(permitted_store_params)

  if @store.save
    flash[:success] = flash_message_for(@store, :successfully_created)
    redirect_to spree.admin_url(domain: @store.url), allow_other_host: true
  else
    flash[:error] = "#{Spree.t('store_errors.unable_to_create')}: #{@store.errors.full_messages.join(', ')}"
    render :new, status: :unprocessable_entity
  end
end

#destroy ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/spree/admin/stores_controller.rb', line 39

def destroy
  @store = stores_scope.find(params[:id])

  if @store.destroy
    flash[:success] = flash_message_for(@store, :successfully_removed)
    redirect_to spree.admin_url(domain: Spree::Store.default.url), allow_other_host: true
  else
    render plain: "#{Spree.t('store_errors.unable_to_delete')}: #{@store.errors.full_messages.join(', ')}", status: :unprocessable_entity
  end
end

#update ⇒ Object



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

def update
  @store.assign_attributes(permitted_store_params)

  if @store.save
    flash[:success] = flash_message_for(@store, :successfully_updated)
  else
    flash[:error] = "#{Spree.t('store_errors.unable_to_update')}: #{@store.errors.full_messages.join(', ')}"
  end

  redirect_to spree.edit_admin_store_path(@store)
end