Class: Releaf::ActionController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Releaf::ActionController
show all
- Includes:
- Ajax, Breadcrumbs, Builders, Exceptions, Features, Layout, Notifications, Resources, RichtextAttachments, Search, Urls, Views, Responders
- Defined in:
- app/controllers/releaf/action_controller.rb
Defined Under Namespace
Modules: Ajax, Breadcrumbs, Builders, Exceptions, Features, Layout, 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 Exceptions
#access_denied, #page_not_found
Methods included from Layout
#layout_features
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
#collection_given? ⇒ Boolean
Returns true if @collection is assigned (even if it’s nil)
129
130
131
|
# File 'app/controllers/releaf/action_controller.rb', line 129
def collection_given?
!!defined? @collection
end
|
#confirm_destroy ⇒ Object
61
62
63
64
65
|
# File 'app/controllers/releaf/action_controller.rb', line 61
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)
151
152
153
|
# File 'app/controllers/releaf/action_controller.rb', line 151
def controller_scope_name
@controller_scope_name ||= 'admin.' + self.class.name.sub(/Controller$/, '').underscore.tr('/', '_')
end
|
#create ⇒ Object
49
50
51
52
53
|
# File 'app/controllers/releaf/action_controller.rb', line 49
def create
prepare_create
@resource.save
respond_with(@resource, location: (success_path if @resource.persisted?), redirect: true)
end
|
#create_another? ⇒ Boolean
137
138
139
|
# File 'app/controllers/releaf/action_controller.rb', line 137
def create_another?
params[:after_save] == "create_another" && feature_available?(:create_another)
end
|
#destroy ⇒ Object
72
73
74
75
76
|
# File 'app/controllers/releaf/action_controller.rb', line 72
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
44
45
46
47
|
# File 'app/controllers/releaf/action_controller.rb', line 44
def edit
prepare_edit
respond_with(@resource)
end
|
#index ⇒ Object
26
27
28
29
|
# File 'app/controllers/releaf/action_controller.rb', line 26
def index
prepare_index
respond_with(@collection)
end
|
#new ⇒ Object
31
32
33
34
|
# File 'app/controllers/releaf/action_controller.rb', line 31
def new
prepare_new
respond_with(@resource)
end
|
#page_title ⇒ Object
155
156
157
158
159
160
|
# File 'app/controllers/releaf/action_controller.rb', line 155
def page_title
title = Rails.application.class.parent_name
title = "#{definition.localized_name} - #{title}" if definition
title
end
|
#prepare_create ⇒ Object
95
96
97
98
99
|
# File 'app/controllers/releaf/action_controller.rb', line 95
def prepare_create
new_resource unless resource_given?
@resource.assign_attributes(resource_params)
end
|
#prepare_destroy ⇒ Object
120
121
122
|
# File 'app/controllers/releaf/action_controller.rb', line 120
def prepare_destroy
load_resource
end
|
#prepare_edit ⇒ Object
105
106
107
|
# File 'app/controllers/releaf/action_controller.rb', line 105
def prepare_edit
prepare_resource_view
end
|
#prepare_index ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'app/controllers/releaf/action_controller.rb', line 78
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
89
90
91
92
93
|
# File 'app/controllers/releaf/action_controller.rb', line 89
def prepare_new
new_resource unless resource_given?
add_resource_breadcrumb(@resource)
end
|
#prepare_resource_view ⇒ Object
109
110
111
112
113
|
# File 'app/controllers/releaf/action_controller.rb', line 109
def prepare_resource_view
load_resource unless resource_given?
add_resource_breadcrumb(@resource)
end
|
#prepare_show ⇒ Object
101
102
103
|
# File 'app/controllers/releaf/action_controller.rb', line 101
def prepare_show
prepare_resource_view
end
|
124
125
126
|
# File 'app/controllers/releaf/action_controller.rb', line 124
def prepare_toolbox
load_resource
end
|
#prepare_update ⇒ Object
115
116
117
118
|
# File 'app/controllers/releaf/action_controller.rb', line 115
def prepare_update
load_resource unless resource_given?
end
|
#required_params ⇒ Object
133
134
135
|
# File 'app/controllers/releaf/action_controller.rb', line 133
def required_params
params.require(:resource)
end
|
#short_name ⇒ Object
162
163
164
|
# File 'app/controllers/releaf/action_controller.rb', line 162
def short_name
self.class.name.sub(/Controller$/, "").underscore
end
|
#show ⇒ Object
36
37
38
39
40
41
42
|
# File 'app/controllers/releaf/action_controller.rb', line 36
def show
if feature_available?(:show)
prepare_show
else
redirect_to url_for(action: 'edit', id: params[:id])
end
end
|
67
68
69
70
|
# File 'app/controllers/releaf/action_controller.rb', line 67
def toolbox
prepare_toolbox
respond_with(@resource)
end
|
#update ⇒ Object
55
56
57
58
59
|
# File 'app/controllers/releaf/action_controller.rb', line 55
def update
prepare_update
@resource.update_attributes(resource_params)
respond_with(@resource, location: success_path)
end
|