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)
130
131
132
|
# File 'app/controllers/releaf/action_controller.rb', line 130
def collection_given?
!!defined? @collection
end
|
#confirm_destroy ⇒ Object
62
63
64
65
66
|
# File 'app/controllers/releaf/action_controller.rb', line 62
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)
152
153
154
|
# File 'app/controllers/releaf/action_controller.rb', line 152
def controller_scope_name
@controller_scope_name ||= 'admin.' + self.class.name.sub(/Controller$/, '').underscore.tr('/', '_')
end
|
#create ⇒ Object
50
51
52
53
54
|
# File 'app/controllers/releaf/action_controller.rb', line 50
def create
prepare_create
@resource.save
respond_with(@resource, location: (success_path if @resource.persisted?), redirect: true)
end
|
#create_another? ⇒ Boolean
138
139
140
|
# File 'app/controllers/releaf/action_controller.rb', line 138
def create_another?
params[:after_save] == "create_another" && feature_available?(:create_another)
end
|
#destroy ⇒ Object
73
74
75
76
77
|
# File 'app/controllers/releaf/action_controller.rb', line 73
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
45
46
47
48
|
# File 'app/controllers/releaf/action_controller.rb', line 45
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
156
157
158
159
160
161
|
# File 'app/controllers/releaf/action_controller.rb', line 156
def page_title
title = Rails.application.class.parent_name
title = "#{definition.localized_name} - #{title}" if definition
title
end
|
#prepare_create ⇒ Object
96
97
98
99
100
|
# File 'app/controllers/releaf/action_controller.rb', line 96
def prepare_create
new_resource unless resource_given?
@resource.assign_attributes(resource_params)
end
|
#prepare_destroy ⇒ Object
121
122
123
|
# File 'app/controllers/releaf/action_controller.rb', line 121
def prepare_destroy
load_resource
end
|
#prepare_edit ⇒ Object
106
107
108
|
# File 'app/controllers/releaf/action_controller.rb', line 106
def prepare_edit
prepare_resource_view
end
|
#prepare_index ⇒ Object
79
80
81
82
83
84
85
86
87
88
|
# File 'app/controllers/releaf/action_controller.rb', line 79
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
90
91
92
93
94
|
# File 'app/controllers/releaf/action_controller.rb', line 90
def prepare_new
new_resource unless resource_given?
add_resource_breadcrumb(@resource)
end
|
#prepare_resource_view ⇒ Object
110
111
112
113
114
|
# File 'app/controllers/releaf/action_controller.rb', line 110
def prepare_resource_view
load_resource unless resource_given?
add_resource_breadcrumb(@resource)
end
|
#prepare_show ⇒ Object
102
103
104
|
# File 'app/controllers/releaf/action_controller.rb', line 102
def prepare_show
prepare_resource_view
end
|
125
126
127
|
# File 'app/controllers/releaf/action_controller.rb', line 125
def prepare_toolbox
load_resource
end
|
#prepare_update ⇒ Object
116
117
118
119
|
# File 'app/controllers/releaf/action_controller.rb', line 116
def prepare_update
load_resource unless resource_given?
end
|
#required_params ⇒ Object
134
135
136
|
# File 'app/controllers/releaf/action_controller.rb', line 134
def required_params
params.require(:resource)
end
|
#short_name ⇒ Object
163
164
165
|
# File 'app/controllers/releaf/action_controller.rb', line 163
def short_name
self.class.name.sub(/Controller$/, "").underscore
end
|
#show ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'app/controllers/releaf/action_controller.rb', line 36
def show
if feature_available?(:show)
prepare_show
respond_with(@resource)
else
redirect_to url_for(action: 'edit', id: params[:id])
end
end
|
68
69
70
71
|
# File 'app/controllers/releaf/action_controller.rb', line 68
def toolbox
prepare_toolbox
respond_with(@resource)
end
|
#update ⇒ Object
56
57
58
59
60
|
# File 'app/controllers/releaf/action_controller.rb', line 56
def update
prepare_update
@resource.update_attributes(resource_params)
respond_with(@resource, location: success_path)
end
|