Class: Adminsite::Admin::ResourcesController
- Inherits:
-
CrudController
- Object
- CrudController
- Adminsite::Admin::ResourcesController
show all
- Defined in:
- app/controllers/adminsite/admin/resources_controller.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
140
141
142
143
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 140
def
pattern = "^#{resource_class.to_s.deconstantize.split('::').join('|^')}"
super.gsub(/#{pattern}/,'')
end
|
.register_routes(rails_router) ⇒ Object
149
150
151
152
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 149
def register_routes(rails_router)
return if self == Adminsite::Admin::ResourcesController
super(rails_router)
end
|
.remove_namespace(string, namespaces) ⇒ Object
145
146
147
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 145
def remove_namespace(string, namespaces)
(string.split('/') - namespaces).join('/')
end
|
.resource_class ⇒ Object
154
155
156
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 154
def resource_class
raise NotImplementedError.new('Define resource_class in subclass')
end
|
Instance Method Details
#admin_resource_path(id = nil, action = nil, options = {}) ⇒ Object
83
84
85
86
87
88
89
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 83
def admin_resource_path(id = nil, action = nil, options = {})
path = self.class.remove_namespace(params[:controller], ['adminsite'])
path = path.gsub('/','_')
path = path.singularize if (action || id).present? && action.to_s != 'search'
path = "#{action}_#{path}" if action.present?
send("#{path}_path", id, {admin_menu: }.merge(options) )
end
|
#authorize_resource_class ⇒ Object
67
68
69
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 67
def authorize_resource_class
resource_class
end
|
#create ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 14
def create
@resource ||= self.class.resource_class.new(resource_params)
if @resource.save
flash_notice_success('created')
if api_call?
render :json => @resource
else
redirect_to admin_resource_path(@resource.id)
end
else
render :action => "new"
end
end
|
79
80
81
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 79
def
||= params[:admin_menu]
end
|
#destroy ⇒ Object
58
59
60
61
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 58
def destroy
@resource.destroy
redirect_to admin_resource_path
end
|
#edit ⇒ Object
29
30
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 29
def edit
end
|
#index ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 49
def index
@q = scope_resources.ransack(params[:q])
@resources = @q.result.order(order_params).page(params[:page])
@ransack_params = ransack_params
@search_params = @ransack_params[:q].try(:except, :s)
@show_search_form = @search_params.present?
render :json => @resources if api_call?
end
|
#new ⇒ Object
10
11
12
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 10
def new
@resource ||= self.class.resource_class.new
end
|
#ransack_params ⇒ Object
75
76
77
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 75
def ransack_params
params.slice(:q, :p).each{|k,v| v.delete_if {|key, value| value.blank? }}
end
|
#resource_class ⇒ Object
63
64
65
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 63
def resource_class
self.class.resource_class
end
|
#resource_class_underscore ⇒ Object
71
72
73
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 71
def resource_class_underscore
@resource_class_underscore ||= resource_class.to_s.underscore.gsub('/','_')
end
|
#show ⇒ Object
32
33
34
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 32
def show
render :json => @resource if api_call?
end
|
#update ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/adminsite/admin/resources_controller.rb', line 36
def update
if @resource.update_attributes(resource_params)
flash_notice_success('updated')
if api_call?
render :json => @resource
else
redirect_to admin_resource_path(@resource.id, :edit)
end
else
render :action => "edit"
end
end
|