Class: Spree::Admin::ResourceController
Direct Known Subclasses
AdjustmentReasonsController, AdjustmentsController, CustomerReturnsController, ImagesController, OptionTypesController, PaymentMethodsController, PricesController, ProductPropertiesController, ProductsController, PropertiesController, RefundReasonsController, RefundsController, ReimbursementTypesController, ReimbursementsController, ReturnAuthorizationsController, ReturnItemsController, ReturnReasonsController, ShippingCategoriesController, ShippingMethodsController, StockItemsController, StockLocationsController, StockMovementsController, StoreCreditReasonsController, StoreCreditsController, StoresController, TaxCategoriesController, TaxRatesController, TaxonomiesController, UsersController, VariantPropertyRuleValuesController, VariantsController, ZonesController
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#set_user_language_locale_key
Class Attribute Details
.parent_data ⇒ Object
Returns the value of attribute parent_data.
135
136
137
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 135
def parent_data
@parent_data
end
|
Class Method Details
.belongs_to(model_name, options = {}) ⇒ Object
137
138
139
140
141
142
143
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 137
def belongs_to(model_name, options = {})
@parent_data ||= {}
@parent_data[:model_name] = model_name
@parent_data[:model_class] = (options[:model_class] || model_name.to_s.classify.constantize)
@parent_data[:find_by] = options[:find_by] || :id
@parent_data[:includes] = options[:includes]
end
|
Instance Method Details
#create ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 57
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.html { redirect_to location_after_save }
format.js { render layout: false }
end
else
invoke_callbacks(:create, :fails)
respond_with(@object) do |format|
format.html do
flash.now[:error] = @object.errors.full_messages.join(", ")
render_after_create_error
end
format.js { render layout: false }
end
end
end
|
#destroy ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 100
def destroy
invoke_callbacks(:destroy, :before)
destroy_result =
if @object.respond_to?(:discard)
@object.discard
else
@object.destroy
end
if destroy_result
invoke_callbacks(:destroy, :after)
flash[:success] = flash_message_for(@object, :successfully_removed)
respond_with(@object) do |format|
format.html { redirect_to location_after_destroy }
format.js { render partial: "spree/admin/shared/destroy" }
end
else
invoke_callbacks(:destroy, :fails)
respond_with(@object) do |format|
message = @object.errors.full_messages.to_sentence
format.html do
flash[:error] = message
redirect_to location_after_destroy
end
format.js do
render status: :unprocessable_entity, plain: message
end
end
end
end
|
#edit ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 25
def edit
respond_with(@object) do |format|
format.html { render layout: !request.xhr? }
if request.xhr?
format.js { render layout: false }
end
end
end
|
#new ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 15
def new
invoke_callbacks(:new_action, :before)
respond_with(@object) do |format|
format.html { render layout: !request.xhr? }
if request.xhr?
format.js { render layout: false }
end
end
end
|
#update ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 34
def update
invoke_callbacks(:update, :before)
if @object.update(permitted_resource_params)
invoke_callbacks(:update, :after)
respond_with(@object) do |format|
format.html do
flash[:success] = flash_message_for(@object, :successfully_updated)
redirect_to location_after_save
end
format.js { render layout: false }
end
else
invoke_callbacks(:update, :fails)
respond_with(@object) do |format|
format.html do
flash.now[:error] = @object.errors.full_messages.join(", ")
render_after_update_error
end
format.js { render layout: false }
end
end
end
|
#update_positions ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 79
def update_positions
ActiveRecord::Base.transaction do
positions = params[:positions]
positions.each do |id, index|
model_class.where(id:).first&.set_list_position(index)
end
end
respond_to do |format|
format.js { head :no_content }
end
end
|