Class: Releaf::ActionController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Releaf::ActionController
show all
- Includes:
- Ajax, Breadcrumbs, Builders, Features, Notifications, Resources, RichtextAttachments, Search, Urls, Views, Responders
- Defined in:
- app/controllers/releaf/action_controller.rb
Defined Under Namespace
Modules: Ajax, Breadcrumbs, Builders, Features, Notifications, Resources, RichtextAttachments, Search, Urls, Views
Instance Method Summary
collapse
Methods included from Responders
#action_responder, #action_responders, #active_responder, #respond_with
Methods included from Views
#action_view, #action_views, #active_view
#create_releaf_richtext_attachment, #releaf_richtext_attachment_upload_url
#add_resource_breadcrumb, #build_breadcrumbs, #controller_breadcrumb
Methods included from Urls
#current_path, #index_path, #resolve_index_path, #success_path, #valid_index_path?
Methods included from Ajax
#ajax?, #layout, #manage_ajax
Methods included from Features
#action_feature, #action_features, #feature_available?, #feature_disabled, #features, #verify_feature_availability!
Methods included from Search
#search, #searchable_fields, #searcher_class
Methods included from Builders
#application_scope, #builder_class, #builder_scopes
Methods included from Resources
#load_resource, #new_resource, #permitted_params, #resource_class, #resource_given?, #resource_params, #resources, #resources_per_page
#notice_scope_name, #render_notification
Instance Method Details
#access_denied ⇒ Object
140
141
142
|
# File 'app/controllers/releaf/action_controller.rb', line 140
def access_denied
respond_with(nil, responder: action_responder(:access_denied))
end
|
#collection_given? ⇒ Boolean
Returns true if @collection is assigned (even if it’s nil)
128
129
130
|
# File 'app/controllers/releaf/action_controller.rb', line 128
def collection_given?
!!defined? @collection
end
|
#confirm_destroy ⇒ Object
60
61
62
63
64
|
# File 'app/controllers/releaf/action_controller.rb', line 60
def confirm_destroy
prepare_destroy
@restricted_relations = Releaf::ResourceUtilities.restricted_relations(@resource)
respond_with(@resource, destroyable: destroyable?)
end
|
#controller_scope_name ⇒ Object
return contoller translation scope name for using with I18.translation call within hash params ex. t(“save”, scope: controller_scope_name)
154
155
156
|
# File 'app/controllers/releaf/action_controller.rb', line 154
def controller_scope_name
@controller_scope_name ||= 'admin.' + self.class.name.sub(/Controller$/, '').underscore.tr('/', '_')
end
|
#create ⇒ Object
48
49
50
51
52
|
# File 'app/controllers/releaf/action_controller.rb', line 48
def create
prepare_create
@resource.save
respond_with(@resource, location: (success_path if @resource.persisted?), redirect: true)
end
|
#create_another? ⇒ Boolean
136
137
138
|
# File 'app/controllers/releaf/action_controller.rb', line 136
def create_another?
params[:after_save] == "create_another" && feature_available?(:create_another)
end
|
#destroy ⇒ Object
71
72
73
74
75
|
# File 'app/controllers/releaf/action_controller.rb', line 71
def destroy
prepare_destroy
@resource.destroy if destroyable?
respond_with(@resource, location: index_path)
end
|
#destroyable? ⇒ Boolean
Check if @resource has existing restrict relation and it can be deleted
#edit ⇒ Object
43
44
45
46
|
# File 'app/controllers/releaf/action_controller.rb', line 43
def edit
prepare_edit
respond_with(@resource)
end
|
#index ⇒ Object
25
26
27
28
|
# File 'app/controllers/releaf/action_controller.rb', line 25
def index
prepare_index
respond_with(@collection)
end
|
#new ⇒ Object
30
31
32
33
|
# File 'app/controllers/releaf/action_controller.rb', line 30
def new
prepare_new
respond_with(@resource)
end
|
#page_title ⇒ Object
158
159
160
161
162
163
|
# File 'app/controllers/releaf/action_controller.rb', line 158
def page_title
title = Rails.application.class.parent_name
title = "#{definition.localized_name} - #{title}" if definition
title
end
|
#prepare_create ⇒ Object
94
95
96
97
98
|
# File 'app/controllers/releaf/action_controller.rb', line 94
def prepare_create
new_resource unless resource_given?
@resource.assign_attributes(resource_params)
end
|
#prepare_destroy ⇒ Object
119
120
121
|
# File 'app/controllers/releaf/action_controller.rb', line 119
def prepare_destroy
load_resource
end
|
#prepare_edit ⇒ Object
104
105
106
|
# File 'app/controllers/releaf/action_controller.rb', line 104
def prepare_edit
prepare_resource_view
end
|
#prepare_index ⇒ Object
77
78
79
80
81
82
83
84
85
86
|
# File 'app/controllers/releaf/action_controller.rb', line 77
def prepare_index
@collection = resources unless collection_given?
search(params[:search])
unless resources_per_page.nil?
@collection = @collection.page( params[:page] ).per_page( resources_per_page )
end
end
|
#prepare_new ⇒ Object
88
89
90
91
92
|
# File 'app/controllers/releaf/action_controller.rb', line 88
def prepare_new
new_resource unless resource_given?
add_resource_breadcrumb(@resource)
end
|
#prepare_resource_view ⇒ Object
108
109
110
111
112
|
# File 'app/controllers/releaf/action_controller.rb', line 108
def prepare_resource_view
load_resource unless resource_given?
add_resource_breadcrumb(@resource)
end
|
#prepare_show ⇒ Object
100
101
102
|
# File 'app/controllers/releaf/action_controller.rb', line 100
def prepare_show
prepare_resource_view
end
|
123
124
125
|
# File 'app/controllers/releaf/action_controller.rb', line 123
def prepare_toolbox
load_resource
end
|
#prepare_update ⇒ Object
114
115
116
117
|
# File 'app/controllers/releaf/action_controller.rb', line 114
def prepare_update
load_resource unless resource_given?
end
|
#required_params ⇒ Object
132
133
134
|
# File 'app/controllers/releaf/action_controller.rb', line 132
def required_params
params.require(:resource)
end
|
#short_name ⇒ Object
165
166
167
|
# File 'app/controllers/releaf/action_controller.rb', line 165
def short_name
self.class.name.sub(/Controller$/, "").underscore
end
|
#show ⇒ Object
35
36
37
38
39
40
41
|
# File 'app/controllers/releaf/action_controller.rb', line 35
def show
if feature_available?(:show)
prepare_show
else
redirect_to url_for(action: 'edit', id: params[:id])
end
end
|
66
67
68
69
|
# File 'app/controllers/releaf/action_controller.rb', line 66
def toolbox
prepare_toolbox
respond_with(@resource)
end
|
#update ⇒ Object
54
55
56
57
58
|
# File 'app/controllers/releaf/action_controller.rb', line 54
def update
prepare_update
@resource.update_attributes(resource_params)
respond_with(@resource, location: success_path)
end
|