Class: Alchemy::Custom::Model::Admin::BaseController
- Inherits:
-
Object
- Object
- Alchemy::Custom::Model::Admin::BaseController
show all
- Defined in:
- app/controllers/alchemy/custom/model/admin/base_controller.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.belongs_to(model_name, options = {}) ⇒ Object
104
105
106
107
108
109
110
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 104
def belongs_to(model_name, options = {})
prepend_before_action :load_parent
const_model_klass = options[:model_klass].to_s.constantize unless options[:model_klass].nil?
self.parent_model_name = model_name.to_s
self.parent_klass = const_model_klass || self.parent_model_name.to_s.classify.constantize
self.parent_find_method = options[:find_by].to_s || "id"
end
|
Instance Method Details
#create ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 55
def create
if @obj.update_attributes(clean_params)
after_successful_create
else
after_unsuccessful_create
end
end
|
#destroy ⇒ Object
47
48
49
50
51
52
53
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 47
def destroy
if @obj.destroy
after_successful_destroy
else
after_unsuccessful_destroy
end
end
|
#edit ⇒ Object
35
36
37
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 35
def edit
end
|
#export_csv ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 81
def export_csv
@query = base_class.ransack(params[:q])
@objects = @query.result(distinct: true)
@objects = @objects.accessible_by(current_ability)
@total_objects = @objects
send_data generate_csv, filename: "export_member.csv", disposition: :attachment, type: "text/csv"
end
|
#export_csv_full ⇒ Object
94
95
96
97
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 94
def export_csv_full
@objects = base_class.all.accessible_by(current_ability)
send_data generate_csv, filename: "export_member.csv", disposition: :attachment, type: "text/csv"
end
|
#index ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 19
def index
@query = base_class.ransack(params[:q])
@objects = @query.result(distinct: true)
@objects = @objects.accessible_by(current_ability).only_current_language
@total_objects = @objects
@objects = @objects.page(params[:page]).
per(params[:per_page] ||
(base_class::DEFAULT_PER_PAGE if base_class.const_defined? :DEFAULT_PER_PAGE) ||
25)
instance_variable_set "@#{base_class.name.demodulize.underscore.downcase.pluralize}", @objects
end
|
#new ⇒ Object
31
32
33
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 31
def new
end
|
#show ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 64
def show
unless self.class.method_for_show.nil?
if @obj.respond_to? self.class.method_for_show
@objects = @obj.send(self.class.method_for_show.to_sym)
@objects = @objects.accessible_by(current_ability)
@total_objects = @objects
@objects = @objects.page(params[:page]).
per(params[:per_page] ||
(base_class::DEFAULT_PER_PAGE if base_class.const_defined? :DEFAULT_PER_PAGE) ||
25)
instance_variable_set "@#{self.class.method_for_show.to_s.underscore.downcase.pluralize}", @objects
else
@objects = base_class.none
end
end
end
|
#update ⇒ Object
39
40
41
42
43
44
45
|
# File 'app/controllers/alchemy/custom/model/admin/base_controller.rb', line 39
def update
if @obj.update_attributes(clean_params)
after_successful_update
else
atfer_unsuccessful_update
end
end
|