Class: CrudComponents::Admin::ResourcesController
Overview
Every registered model's CRUD, in one controller. The model comes from the
route's crud_model default, so a request can only ever name a model the
registry drew a route for.
Constant Summary
ApplicationController::ACTIVE_STORAGE_HELPERS
Instance Method Summary
collapse
Instance Method Details
#create ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 24
def create
@record.assign_attributes(record_params(:create))
if @record.save
redirect_to after_save_path(@record), notice: saved_notice(:created)
else
render :new, status: :unprocessable_entity
end
end
|
#delete ⇒ Object
The confirmation step, for one record or for the ticked rows: which they
are, and what goes with them.
43
44
45
46
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 43
def delete
@records = [@record]
@dependents = Dependents::Selection.new(@records)
end
|
#delete_selected ⇒ Object
48
49
50
51
52
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 48
def delete_selected
@records = selected_records
@dependents = Dependents::Selection.new(@records)
render :delete
end
|
#destroy ⇒ Object
54
55
56
57
58
59
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 54
def destroy
@record.destroy!
redirect_to index_path, notice: saved_notice(:destroyed)
rescue ActiveRecord::InvalidForeignKey, ActiveRecord::DeleteRestrictionError => e
redirect_to after_save_path(@record), alert: e.message
end
|
#destroy_selected ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 61
def destroy_selected
records = selected_records
records.each(&:destroy!)
redirect_to index_path,
notice: t('crud_components.admin.notices.destroyed_selected', count: records.size,
default: '%{count} deleted.')
rescue ActiveRecord::InvalidForeignKey, ActiveRecord::DeleteRestrictionError => e
redirect_to index_path, alert: e.message
end
|
#edit ⇒ Object
22
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 22
def edit; end
|
#index ⇒ Object
12
13
14
15
16
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 12
def index
@owner = owner
@query = CrudComponents::Query.new(@model, params, fieldset: @entry.fieldset, ability: admin_ability)
@records = paginate(@query.apply(base_scope))
end
|
#new ⇒ Object
20
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 20
def new; end
|
#show ⇒ Object
18
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 18
def show; end
|
#update ⇒ Object
33
34
35
36
37
38
39
|
# File 'app/controllers/crud_components/admin/resources_controller.rb', line 33
def update
if @record.update(record_params(:update))
redirect_to after_save_path(@record), notice: saved_notice(:updated)
else
render :edit, status: :unprocessable_entity
end
end
|