Class: Spree::Admin::ResourceController
Direct Known Subclasses
AdjustmentsController, CountriesController, ImagesController, OptionTypesController, PaymentMethodsController, ProductPropertiesController, ProductsController, PromotionsController, PropertiesController, PrototypesController, ReturnAuthorizationsController, ShippingCategoriesController, ShippingMethodsController, StatesController, StockLocationsController, TaxCategoriesController, TaxRatesController, TaxonomiesController, TrackersController, VariantsController, ZonesController
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.callbacks ⇒ Object
Returns the value of attribute callbacks.
96
97
98
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 96
def callbacks
@callbacks
end
|
.parent_data ⇒ Object
Returns the value of attribute parent_data.
95
96
97
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 95
def parent_data
@parent_data
end
|
Class Method Details
.belongs_to(model_name, options = {}) ⇒ Object
98
99
100
101
102
103
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 98
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
|
.create ⇒ Object
110
111
112
113
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 110
def create
@callbacks ||= {}
@callbacks[:create] ||= Spree::ActionCallbacks.new
end
|
.destroy ⇒ Object
120
121
122
123
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 120
def destroy
@callbacks ||= {}
@callbacks[:destroy] ||= Spree::ActionCallbacks.new
end
|
.new_action ⇒ Object
105
106
107
108
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 105
def new_action
@callbacks ||= {}
@callbacks[:new_action] ||= Spree::ActionCallbacks.new
end
|
.update ⇒ Object
115
116
117
118
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 115
def update
@callbacks ||= {}
@callbacks[:update] ||= Spree::ActionCallbacks.new
end
|
Instance Method Details
#create ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 44
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)
end
end
|
#destroy ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 70
def destroy
invoke_callbacks(:destroy, :before)
if @object.destroy
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|
format.html { redirect_to location_after_destroy }
end
end
end
|
#edit ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 20
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
10
11
12
13
14
15
16
17
18
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 10
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 29
def update
invoke_callbacks(:update, :before)
if @object.update_attributes(permitted_resource_params)
invoke_callbacks(:update, :after)
flash[:success] = flash_message_for(@object, :successfully_updated)
respond_with(@object) do |format|
format.html { redirect_to location_after_save }
format.js { render :layout => false }
end
else
invoke_callbacks(:update, :fails)
respond_with(@object)
end
end
|
#update_positions ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'app/controllers/spree/admin/resource_controller.rb', line 60
def update_positions
params[:positions].each do |id, index|
model_class.where(:id => id).update_all(:position => index)
end
respond_to do |format|
format.js { render :text => 'Ok' }
end
end
|