Class: Stay::Admin::StoresController

Inherits:
BaseController show all
Defined in:
app/controllers/stay/admin/stores_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#load_stores, #set_currency, #set_current_store, #stores_scope

Methods included from ControllerHelpers::Store

#current_store, #ensure_current_store, #store_locale

Methods included from ControllerHelpers::Currency

#currency_param, #current_currency, #supported_currencies, #supported_currencies_for_all_stores, #supported_currency?

Methods inherited from Stay::ApplicationController

#after_sign_in_path_for, #current_store

Methods included from LocaleHelper

#all_locales_options, #available_locales, #available_locales_options, #config_locale?, #current_locale, #find_with_fallback_default_locale, #locale_full_name, #locale_param, #locale_presentation, #params_locale?, #should_render_locale_dropdown?, #supported_locale?, #supported_locales, #supported_locales_for_all_stores, #supported_locales_options, #user_locale?

Methods included from CurrencyHelper

#currency_options, #currency_presentation, #currency_symbol, #should_render_currency_dropdown?, #supported_currency_options

Instance Method Details

#createObject

POST /admin/stores



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

def create
  @store = Stay::Store.new(store_params)

  if @store.save
    flash[:success] = "Store created successfully"
    redirect_to admin_url, allow_other_host: true
  else
    flash.now[:error] = "Unable to create store."
    render :new
  end
end

#destroyObject

DELETE /admin/stores/:id



58
59
60
61
62
63
64
65
# File 'app/controllers/stay/admin/stores_controller.rb', line 58

def destroy
  if @store.destroy
    flash[:success] = "Store deleted successfully."
  else
    flash[:error] = "Failed to delete the store. Please try again."
  end
  redirect_to admin_stores_path
end

#editObject

GET /admin/stores/:id/edit



40
41
# File 'app/controllers/stay/admin/stores_controller.rb', line 40

def edit
end

#indexObject

GET /admin/stores



17
18
19
# File 'app/controllers/stay/admin/stores_controller.rb', line 17

def index
  @stores = Stay::Store.all
end

#newObject

GET /admin/stores/new



22
23
24
# File 'app/controllers/stay/admin/stores_controller.rb', line 22

def new
  @store = Stay::Store.new
end

#set_defaultObject



67
68
69
70
71
72
73
74
# File 'app/controllers/stay/admin/stores_controller.rb', line 67

def set_default
  Stay::Store.update_all(default: false)
  if @store.update(default: true)
    redirect_to admin_stores_path, notice: 'Store successfully set as default.'
  else
    redirect_to admin_stores_path, alert: 'Failed to set store as default.'
  end
end

#showObject



43
44
# File 'app/controllers/stay/admin/stores_controller.rb', line 43

def show
end

#updateObject

PATCH/PUT /admin/stores/:id



47
48
49
50
51
52
53
54
55
# File 'app/controllers/stay/admin/stores_controller.rb', line 47

def update
  if @store.update(store_params)
    flash[:success] = "Store Update Successfully"
    redirect_to admin_stores_path
  else
    flash.now[:error] = "Unable to update store."
    render :edit
  end
end