Class: Spree::Admin::ResourceController
Direct Known Subclasses
AdjustmentsController, CmsPagesController, CmsSectionsController, CountriesController, CustomerReturnsController, DataFeedsController, DigitalsController, ImagesController, MenuItemsController, MenusController, OauthApplicationsController, OptionTypesController, OptionValuesController, PaymentMethodsController, PricesController, ProductPropertiesController, ProductsController, PromotionCategoriesController, PromotionsController, PropertiesController, PrototypesController, RefundReasonsController, RefundsController, ReimbursementTypesController, ReimbursementsController, ReturnAuthorizationReasonsController, ReturnAuthorizationsController, ReturnItemsController, RolesController, ShippingCategoriesController, ShippingMethodsController, StatesController, StockLocationsController, StoreCreditCategoriesController, TaxCategoriesController, TaxRatesController, TaxonomiesController, TaxonsController, UsersController, VariantsController, WebhooksSubscribersController, ZonesController
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.parent_data ⇒ Object
Returns the value of attribute parent_data.
102
103
104
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 102
def parent_data
@parent_data
end
|
Class Method Details
.belongs_to(model_name, options = {}) ⇒ Object
104
105
106
107
108
109
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 104
def belongs_to(model_name, options = {})
@parent_data ||= {}
@parent_data[:model_name] = model_name
@parent_data[:model_class] = model_name.to_s.classify.constantize
@parent_data[:find_by] = options[:find_by] || :id
end
|
Instance Method Details
#create ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 49
def create
invoke_callbacks(:create, :before)
@object.attributes = permitted_resource_params
if @object.save
invoke_callbacks(:create, :after)
flash[:success] = flash_message_for(@object, :successfully_created)
respond_with(@object) do |format|
format.turbo_stream if create_turbo_stream_enabled?
format.html { redirect_to location_after_save }
format.js { render layout: false }
end
else
invoke_callbacks(:create, :fails)
respond_with(@object) do |format|
format.html { render action: :new, status: :unprocessable_entity }
format.js { render layout: false, status: :unprocessable_entity }
end
end
end
|
#destroy ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 83
def destroy
invoke_callbacks(:destroy, :before)
if @object.destroy
invoke_callbacks(:destroy, :after)
flash[:success] = flash_message_for(@object, :successfully_removed)
else
invoke_callbacks(:destroy, :fails)
flash[:error] = @object.errors.full_messages.join(', ')
end
respond_with(@object) do |format|
format.html { redirect_to location_after_destroy }
format.js { render_js_for_destroy }
end
end
|
#edit ⇒ Object
20
21
22
23
24
25
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 20
def edit
respond_with(@object) do |format|
format.html { render layout: !request.xhr? }
format.js { render layout: false } if request.xhr?
end
end
|
#new ⇒ Object
12
13
14
15
16
17
18
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 12
def new
invoke_callbacks(:new_action, :before)
respond_with(@object) do |format|
format.html { render layout: !request.xhr? }
format.js { render layout: false } if request.xhr?
end
end
|
#update ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 27
def update
invoke_callbacks(:update, :before)
if @object.update(permitted_resource_params)
set_current_store
invoke_callbacks(:update, :after)
respond_with(@object) do |format|
format.turbo_stream if update_turbo_stream_enabled?
format.html do
flash[:success] = flash_message_for(@object, :successfully_updated)
redirect_to location_after_save unless request.xhr?
end
format.js { render layout: false }
end
else
invoke_callbacks(:update, :fails)
respond_with(@object) do |format|
format.html { render action: :edit, status: :unprocessable_entity }
format.js { render layout: false, status: :unprocessable_entity }
end
end
end
|
#update_positions ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 69
def update_positions
base_scope = model_class.try(:for_store, current_store) || model_class
ApplicationRecord.transaction do
params[:positions].each do |id, index|
base_scope.find(id).set_list_position(index)
end
end
respond_to do |format|
format.js { head :ok }
end
end
|