Class: Admin::ResourceController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::ResourceController
show all
- Defined in:
- app/controllers/admin/resource_controller.rb
Direct Known Subclasses
AdjustmentsController, ImagesController, MailMethodsController, OptionTypesController, PaymentMethodsController, ProductGroupsController, ProductPropertiesController, ProductsController, PropertiesController, PrototypesController, ReturnAuthorizationsController, ShippingCategoriesController, ShippingMethodsController, StatesController, TaxCategoriesController, TaxRatesController, TaxonomiesController, TrackersController, UsersController, 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.
74
75
76
|
# File 'app/controllers/admin/resource_controller.rb', line 74
def callbacks
@callbacks
end
|
.parent_data ⇒ Object
Returns the value of attribute parent_data.
73
74
75
|
# File 'app/controllers/admin/resource_controller.rb', line 73
def parent_data
@parent_data
end
|
Class Method Details
.belongs_to(model_name, options = {}) ⇒ Object
76
77
78
79
80
81
|
# File 'app/controllers/admin/resource_controller.rb', line 76
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
83
84
85
86
|
# File 'app/controllers/admin/resource_controller.rb', line 83
def create
@callbacks ||= {}
@callbacks[:create] ||= Spree::ActionCallbacks.new
end
|
.destroy ⇒ Object
93
94
95
96
|
# File 'app/controllers/admin/resource_controller.rb', line 93
def destroy
@callbacks ||= {}
@callbacks[:destroy] ||= Spree::ActionCallbacks.new
end
|
.update ⇒ Object
88
89
90
91
|
# File 'app/controllers/admin/resource_controller.rb', line 88
def update
@callbacks ||= {}
@callbacks[:update] ||= Spree::ActionCallbacks.new
end
|
Instance Method Details
#create ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/controllers/admin/resource_controller.rb', line 38
def create
invoke_callbacks(:create, :before)
if @object.save
invoke_callbacks(:create, :after)
flash[:notice] = 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'app/controllers/admin/resource_controller.rb', line 53
def destroy
invoke_callbacks(:destroy, :before)
if @object.destroy
invoke_callbacks(:destroy, :after)
flash[:notice] = flash_message_for(@object, :successfully_removed)
respond_with(@object) do |format|
format.html { redirect_to collection_url }
format.js { render :partial => "/admin/shared/destroy" }
end
else
invoke_callbacks(:destroy, :fails)
respond_with(@object) do |format|
format.html { redirect_to collection_url }
end
end
end
|
#edit ⇒ Object
16
17
18
19
20
21
|
# File 'app/controllers/admin/resource_controller.rb', line 16
def edit
respond_with(@object) do |format|
format.html { render :layout => !request.xhr? }
format.js { render :layout => false }
end
end
|
#new ⇒ Object
9
10
11
12
13
14
|
# File 'app/controllers/admin/resource_controller.rb', line 9
def new
respond_with(@object) do |format|
format.html { render :layout => !request.xhr? }
format.js { render :layout => false }
end
end
|
#update ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/admin/resource_controller.rb', line 23
def update
invoke_callbacks(:update, :before)
if @object.update_attributes(params[object_name])
invoke_callbacks(:update, :after)
flash[:notice] = 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
|