Class: Terrazzo::ApplicationController
Instance Method Summary
collapse
#terrazzo_resource_collection_path, #terrazzo_resource_controller_path, #terrazzo_resource_member_path, #terrazzo_resource_new_path, #terrazzo_resource_param
#_render_template
Instance Method Details
#create ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/controllers/terrazzo/application_controller.rb', line 70
def create
@resource = resource_class.new
authorize_action!(@resource, :create)
@resource.assign_attributes(resource_params("create"))
assign_has_one_associations(@resource)
if @resource.save
redirect_to after_resource_created_path(@resource),
notice: t("terrazzo.controllers.create.success",
resource_name: resource_name)
else
@page = Terrazzo::Page::Form.new(dashboard, @resource)
render :new, status: :unprocessable_entity
end
end
|
#destroy ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'app/controllers/terrazzo/application_controller.rb', line 103
def destroy
@resource = find_resource(params[:id])
authorize_action!(@resource, :destroy)
@resource.destroy
redirect_to after_resource_destroyed_path,
notice: t("terrazzo.controllers.destroy.success",
resource_name: resource_name)
end
|
#edit ⇒ Object
64
65
66
67
68
|
# File 'app/controllers/terrazzo/application_controller.rb', line 64
def edit
@resource = find_resource(params[:id])
authorize_action!(@resource, :edit)
@page = Terrazzo::Page::Form.new(dashboard, @resource)
end
|
#index ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/terrazzo/application_controller.rb', line 24
def index
resources, order = index_resources_and_order
if request.format.csv?
return head :not_acceptable unless dashboard.csv_export_enabled?
includes = dashboard.includes_for_attributes(dashboard.csv_attributes)
resources = resources.includes(*includes) if includes.any?
send_data Terrazzo::CsvExport.new(dashboard, resources).to_csv,
filename: dashboard.csv_filename,
type: "text/csv; charset=utf-8"
return
end
includes = dashboard.collection_includes
resources = resources.includes(*includes) if includes.any?
@resources = resources.page(params[:_page]).per(index_per_page)
@page = Terrazzo::Page::Collection.new(dashboard, resource_class, order: order)
@search_term = params[:search]
@active_filter = params[:filter]
@filter_value = params[:filter_value]
end
|
#new ⇒ Object
58
59
60
61
62
|
# File 'app/controllers/terrazzo/application_controller.rb', line 58
def new
@resource = resource_class.new
authorize_action!(@resource, :new)
@page = Terrazzo::Page::Form.new(dashboard, @resource)
end
|
#show ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'app/controllers/terrazzo/application_controller.rb', line 49
def show
@resource = find_resource(params[:id])
authorize_action!(@resource, :show)
@page = Terrazzo::Page::Show.new(
dashboard, @resource,
has_many_params: Terrazzo::HasManyPagination.(params, dashboard.has_many_attributes)
)
end
|
#update ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/controllers/terrazzo/application_controller.rb', line 86
def update
@resource = find_resource(params[:id])
authorize_action!(@resource, :update)
rp = resource_params("update")
assign_has_one_associations(@resource)
if @resource.update(rp)
redirect_to after_resource_updated_path(@resource),
notice: t("terrazzo.controllers.update.success",
resource_name: resource_name)
else
@page = Terrazzo::Page::Form.new(dashboard, @resource)
render :edit, status: :unprocessable_entity
end
end
|