crudable-rails 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +161 -1
- data/lib/crudable/rails/base.rb +9 -1
- data/lib/crudable/rails/engine.rb +4 -0
- data/lib/crudable/rails/generators/scaffold_controller_extension.rb +55 -0
- data/lib/crudable/rails/generators/scaffold_extension.rb +29 -0
- data/lib/crudable/rails/generators/turbo_forms_generator_option.rb +16 -0
- data/lib/crudable/rails/generators/turbo_forms_scaffold_extension.rb +44 -0
- data/lib/crudable/rails/installer.rb +35 -0
- data/lib/crudable/rails/version.rb +1 -1
- data/lib/crudable-rails.rb +5 -0
- data/lib/generators/crudable/controller/USAGE +23 -0
- data/lib/generators/crudable/controller/controller_generator.rb +19 -0
- data/lib/generators/crudable/controller_helpers.rb +58 -0
- data/lib/generators/crudable/install/USAGE +8 -0
- data/lib/generators/crudable/install/install_generator.rb +19 -0
- data/lib/generators/crudable/scaffold/USAGE +14 -7
- data/lib/generators/crudable/scaffold/scaffold_generator.rb +8 -24
- data/lib/generators/crudable/templates/crudable_controller.rb.tt +257 -0
- data/lib/generators/crudable/templates/turbo_forms/_form.html.erb.tt +37 -0
- data/lib/generators/crudable/templates/turbo_forms/edit.html.erb.tt +14 -0
- data/lib/generators/crudable/templates/turbo_forms/edit.turbo_stream.erb.tt +3 -0
- data/lib/generators/crudable/templates/turbo_forms/new.html.erb.tt +13 -0
- data/lib/generators/crudable/templates/turbo_forms/new.turbo_stream.erb.tt +3 -0
- data/lib/tasks/crudable_tasks.rake +12 -4
- metadata +21 -9
- data/lib/generators/crudable/scaffold/templates/crudable_controller.rb.tt +0 -164
- data/lib/generators/scaffold_controller/USAGE +0 -13
- data/lib/generators/scaffold_controller/scaffold_controller_generator.rb +0 -36
- data/lib/generators/scaffold_controller/templates/crudable_controller.rb.tt +0 -164
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
<% module_namespacing do -%>
|
|
2
|
-
class <%= controller_class_name %>Controller < ApplicationController
|
|
3
|
-
crudable
|
|
4
|
-
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
# ---------------------------------------------------------------------------
|
|
8
|
-
# Optional overrides (self-documenting hooks)
|
|
9
|
-
#
|
|
10
|
-
# `crudable` mixes in `Crudable::Rails::Base` (which includes `Nestable`),
|
|
11
|
-
# which provides the REST actions and calls these hooks. Uncomment and tailor
|
|
12
|
-
# any of the following as needed.
|
|
13
|
-
# ---------------------------------------------------------------------------
|
|
14
|
-
#
|
|
15
|
-
# # If this resource is singular (e.g. SettingsController), return true.
|
|
16
|
-
# def singleton?
|
|
17
|
-
# false
|
|
18
|
-
# end
|
|
19
|
-
#
|
|
20
|
-
# # Which param key to use when finding a member resource (default :id).
|
|
21
|
-
# # Common examples: :slug, :uuid
|
|
22
|
-
# def finder_param
|
|
23
|
-
# :id
|
|
24
|
-
# end
|
|
25
|
-
#
|
|
26
|
-
# # Enable FriendlyId finders/redirects (default false).
|
|
27
|
-
# def friendly_finders?
|
|
28
|
-
# false
|
|
29
|
-
# end
|
|
30
|
-
#
|
|
31
|
-
# # Nested parent lookup: use FriendlyId for the parent (defaults to friendly_finders?).
|
|
32
|
-
# # This is only applied when FriendlyId is available and the parent model responds to `.friendly`.
|
|
33
|
-
# def parent_friendly_finders?
|
|
34
|
-
# friendly_finders?
|
|
35
|
-
# end
|
|
36
|
-
#
|
|
37
|
-
# # Enable pagination (requires Kaminari) (default true when Kaminari is defined).
|
|
38
|
-
# def paginate_resource?
|
|
39
|
-
# super
|
|
40
|
-
# end
|
|
41
|
-
#
|
|
42
|
-
# # Customize the scope used for index. This is the primary hook for filtering.
|
|
43
|
-
# # (HasScope is applied automatically if present.)
|
|
44
|
-
# def authorizable_scope
|
|
45
|
-
# super
|
|
46
|
-
# end
|
|
47
|
-
#
|
|
48
|
-
# # Full scope used for index (after HasScope, Pundit, etc).
|
|
49
|
-
# def resource_scope
|
|
50
|
-
# super
|
|
51
|
-
# end
|
|
52
|
-
#
|
|
53
|
-
# # Skip initializing a new instance in create (useful for custom create flows).
|
|
54
|
-
# def skip_initialize_create?
|
|
55
|
-
# false
|
|
56
|
-
# end
|
|
57
|
-
#
|
|
58
|
-
# # Discard/soft-delete support (requires Discard). When true, destroy will
|
|
59
|
-
# # choose discard vs destroy based on record state and params.
|
|
60
|
-
# def discard?
|
|
61
|
-
# false
|
|
62
|
-
# end
|
|
63
|
-
#
|
|
64
|
-
# # Control whether Pundit authorization should be performed.
|
|
65
|
-
# # Override this to customize authorization behavior (e.g., feature flags, user roles).
|
|
66
|
-
# # Default: returns true when Pundit is defined.
|
|
67
|
-
# def authorize_with_pundit?
|
|
68
|
-
# super
|
|
69
|
-
# end
|
|
70
|
-
#
|
|
71
|
-
# # Authorization lifecycle hooks (called inside create/update).
|
|
72
|
-
# def before_authorize_create; end
|
|
73
|
-
# def after_authorize_create; end
|
|
74
|
-
# def before_authorize_update; end
|
|
75
|
-
# def after_authorize_update; end
|
|
76
|
-
#
|
|
77
|
-
# # Post-success hooks (side-effects, instrumentation, etc).
|
|
78
|
-
# def on_successful_create; end
|
|
79
|
-
# def on_successful_update; end
|
|
80
|
-
#
|
|
81
|
-
# # Failure setup hooks (e.g., rebuild form collections).
|
|
82
|
-
# def on_failed_create_setup; end
|
|
83
|
-
# def on_failed_update_setup; end
|
|
84
|
-
#
|
|
85
|
-
# # Customize success redirects/flash messages.
|
|
86
|
-
# def after_create_redirect_path
|
|
87
|
-
# super
|
|
88
|
-
# end
|
|
89
|
-
#
|
|
90
|
-
# def after_create_notice
|
|
91
|
-
# super
|
|
92
|
-
# end
|
|
93
|
-
#
|
|
94
|
-
# def after_update_redirect_path
|
|
95
|
-
# super
|
|
96
|
-
# end
|
|
97
|
-
#
|
|
98
|
-
# def after_update_notice
|
|
99
|
-
# super
|
|
100
|
-
# end
|
|
101
|
-
#
|
|
102
|
-
# def after_destroy_redirect_path
|
|
103
|
-
# super
|
|
104
|
-
# end
|
|
105
|
-
#
|
|
106
|
-
# def after_failed_destroy_redirect_path
|
|
107
|
-
# super
|
|
108
|
-
# end
|
|
109
|
-
#
|
|
110
|
-
# def after_destroy_notice
|
|
111
|
-
# super
|
|
112
|
-
# end
|
|
113
|
-
#
|
|
114
|
-
# def after_failed_destroy_alert
|
|
115
|
-
# super
|
|
116
|
-
# end
|
|
117
|
-
#
|
|
118
|
-
# # Customize rendering for failed creates/updates (Turbo/HTML).
|
|
119
|
-
# def on_failed_create_render
|
|
120
|
-
# super
|
|
121
|
-
# end
|
|
122
|
-
#
|
|
123
|
-
# def on_failed_update_render
|
|
124
|
-
# super
|
|
125
|
-
# end
|
|
126
|
-
#
|
|
127
|
-
# # Customize rendering for destroy outcomes.
|
|
128
|
-
# def on_successful_destroy_render
|
|
129
|
-
# super
|
|
130
|
-
# end
|
|
131
|
-
#
|
|
132
|
-
# def on_failed_destroy_render
|
|
133
|
-
# super
|
|
134
|
-
# end
|
|
135
|
-
#
|
|
136
|
-
# # Nested resources: parent scoping is automatic when a `*_id` param is present.
|
|
137
|
-
# # Override `use_parent_as_scope?` to disable parent scoping.
|
|
138
|
-
# def find_parent
|
|
139
|
-
# super
|
|
140
|
-
# end
|
|
141
|
-
#
|
|
142
|
-
# def use_parent_as_scope?
|
|
143
|
-
# true
|
|
144
|
-
# end
|
|
145
|
-
#
|
|
146
|
-
# # Nested resources: customize which `*_id` param is treated as the parent id.
|
|
147
|
-
# # Useful for multi-level nesting or non-standard param names.
|
|
148
|
-
# def parent_id_param
|
|
149
|
-
# super
|
|
150
|
-
# end
|
|
151
|
-
#
|
|
152
|
-
# Strong params used by `create` (and by default `update` via `update_params`).
|
|
153
|
-
# Adjust the permitted attributes to match your model and nested params shape.
|
|
154
|
-
def create_params
|
|
155
|
-
<%- if attributes_names.empty? -%>
|
|
156
|
-
params.fetch(:<%= singular_table_name %>, {})
|
|
157
|
-
<%- else -%>
|
|
158
|
-
params.expect(<%= singular_table_name %>: [ <%= permitted_params %> ])
|
|
159
|
-
<%- end -%>
|
|
160
|
-
end
|
|
161
|
-
# By default, updates permit the same attributes as creates.
|
|
162
|
-
alias update_params create_params
|
|
163
|
-
end
|
|
164
|
-
<% end -%>
|