common_core_js 0.3.6 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/FUNDING.yml +4 -0
- data/README.md +12 -5
- data/app/helpers/common_core_helper.rb +2 -3
- data/app/helpers/common_core_js/controller_helper.rb +21 -0
- data/lib/common_core_js.rb +1 -1
- data/lib/common_core_js/version.rb +1 -1
- data/lib/generators/common_core/scaffold_generator.rb +108 -30
- data/lib/generators/common_core/templates/_line.haml +4 -2
- data/lib/generators/common_core/templates/_list.haml +2 -2
- data/lib/generators/common_core/templates/base_controller.rb +3 -0
- data/lib/generators/common_core/templates/controller.rb +19 -9
- data/lib/generators/common_core/templates/create.js.erb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b509c4f6a9d3e9948e5a49a3ea649cb693e75ac47ff43f40cc7bf90e3c96590
|
4
|
+
data.tar.gz: d8336db5c37a0db6d82cd7c926d9d6bd9f1b5cdd97c46e18d35ce30a0126dc77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a49c509c20a0e82c30dbadd3ea700a8eb341e943f6d3347898d09ff3bd0ca29e656302265d9c02784ef0948e7a10bf9a1fd0e31b35dfec52704ea73325bfa30e
|
7
|
+
data.tar.gz: 2d882167e819535280cc20a4bb7ba47c3c35c2a179f4e2ac0170f36f8547a78b364d3cccb8a303a72b117ddc3ee4d06d4f0f08a17eb59b3009917035b4e0dbf8
|
data/FUNDING.yml
ADDED
data/README.md
CHANGED
@@ -8,25 +8,32 @@ Yes, it's opinionated. Yes, it's metaprogramming. A lot of metaprogramming. Ruby
|
|
8
8
|
No, I would not use this to build an intricate app. Yes, it's a great tool for prototyping. Yes, I think prototyping is a lost art.
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
## THE SALES PITCH:
|
12
12
|
* Build plug-and-play scaffolding mixing HAML with jQuery-based Javascript
|
13
13
|
* Automatically Reads Your Models (make them before building your scaffolding!)
|
14
|
-
* Excellent for CRUD, lists with pagination, searching, sorting
|
14
|
+
* Excellent for CRUD, lists with pagination, searching, ~~sorting.~~
|
15
15
|
* Wonderful for prototyping.
|
16
16
|
* Plays nicely with Devise, Kaminari, Haml-Rails, Rspec.
|
17
|
-
* Create specs
|
17
|
+
* Create specs automatically along with the controllers.
|
18
18
|
* Nest your routes model-by-model for built-in poor man's authentication
|
19
19
|
* Throw the scaffolding away when your app is ready to graduate to its next phase.
|
20
20
|
|
21
|
+
## THE BLOG POST
|
21
22
|
|
22
|
-
|
23
|
+
It's really easy to get started by following along with this blog post that creates three simple tables (User, Event, and Format).
|
24
|
+
|
25
|
+
Feel free to build your own tables when you get to the sections for building the 'Event' scaffold:
|
26
|
+
|
27
|
+
https://blog.jasonfleetwoodboldt.com/common-core-js
|
28
|
+
|
29
|
+
## HOW EASY?
|
23
30
|
|
24
31
|
|
25
32
|
```
|
26
33
|
rails generate common_core:scaffold Thing
|
27
34
|
```
|
28
35
|
|
29
|
-
|
36
|
+
## TO INSTALL
|
30
37
|
|
31
38
|
- Add common_core_js to your Gemfile
|
32
39
|
|
@@ -7,7 +7,6 @@ module CommonCoreHelper
|
|
7
7
|
|
8
8
|
|
9
9
|
def datetime_field_localized(form_object, field_name, value, label, timezone = nil )
|
10
|
-
|
11
10
|
res = form_object.label(label,
|
12
11
|
field_name,
|
13
12
|
class: 'small form-text text-muted')
|
@@ -22,6 +21,7 @@ module CommonCoreHelper
|
|
22
21
|
|
23
22
|
|
24
23
|
def date_field_localized(form_object, field_name, value, label, timezone = nil )
|
24
|
+
|
25
25
|
res = form_object.label(label,
|
26
26
|
field_name,
|
27
27
|
class: 'small form-text text-muted')
|
@@ -51,7 +51,7 @@ module CommonCoreHelper
|
|
51
51
|
controller.current_timezone
|
52
52
|
elsif defined?(current_user)
|
53
53
|
if current_user.try(:timezone)
|
54
|
-
Time.now.in_time_zone(current_user.timezone).strftime("%z").to_i/100
|
54
|
+
Time.now.in_time_zone(current_user.timezone.to_i).strftime("%z").to_i/100
|
55
55
|
else
|
56
56
|
Time.now.strftime("%z").to_i/100
|
57
57
|
end
|
@@ -62,7 +62,6 @@ module CommonCoreHelper
|
|
62
62
|
|
63
63
|
|
64
64
|
def date_to_current_timezone(date, timezone = nil)
|
65
|
-
|
66
65
|
# if the timezone is nil, use the server date'
|
67
66
|
if timezone.nil?
|
68
67
|
timezone = Time.now.strftime("%z").to_i/100
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CommonCoreJs
|
2
|
+
module ControllerHelper
|
3
|
+
def modify_date_inputs_on_params(modified_params)
|
4
|
+
use_timezone = current_account.timezone || Time.now.strftime("%z")
|
5
|
+
|
6
|
+
modified_params = modified_params.tap do |params|
|
7
|
+
params.keys.each{|k|
|
8
|
+
if k.ends_with?("_at") || k.ends_with?("_date")
|
9
|
+
|
10
|
+
begin
|
11
|
+
params[k] = DateTime.strptime("#{params[k]} #{use_timezone}", '%Y-%m-%dT%H:%M %z')
|
12
|
+
rescue StandardError
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
modified_params
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/common_core_js.rb
CHANGED
@@ -8,7 +8,7 @@ module CommonCoreJs
|
|
8
8
|
# Your code goes here...
|
9
9
|
#
|
10
10
|
module ControllerHelpers
|
11
|
-
def modify_date_inputs_on_params(modified_params)
|
11
|
+
def modify_date_inputs_on_params(modified_params, authenticated_user = nil)
|
12
12
|
use_timezone = authenticated_user.timezone || Time.now.strftime("%z")
|
13
13
|
|
14
14
|
modified_params = modified_params.tap do |params|
|
@@ -84,16 +84,9 @@ module CommonCore
|
|
84
84
|
end
|
85
85
|
|
86
86
|
auth_assoc = @auth.gsub("current_","")
|
87
|
-
auth_assoc_field = auth_assoc + "_id"
|
88
|
-
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
field==:created_at || field==:id || field == auth_assoc_field.to_sym }
|
93
|
-
rescue StandardError => e
|
94
|
-
puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
|
95
|
-
exit
|
96
|
-
end
|
88
|
+
@no_delete = false
|
89
|
+
@no_create = false
|
97
90
|
|
98
91
|
flags = meta_args[1]
|
99
92
|
flags.each do |f|
|
@@ -106,6 +99,10 @@ module CommonCore
|
|
106
99
|
@specs_only = true
|
107
100
|
when "--no-specs"
|
108
101
|
@no_specs = true
|
102
|
+
when "--no-delete"
|
103
|
+
@no_delete = true
|
104
|
+
when "--no-create"
|
105
|
+
@no_create = true
|
109
106
|
end
|
110
107
|
end
|
111
108
|
|
@@ -114,18 +111,56 @@ module CommonCore
|
|
114
111
|
exit
|
115
112
|
end
|
116
113
|
|
114
|
+
|
115
|
+
# only used for the before_action
|
117
116
|
if @auth_identifier.nil? && !@auth.nil?
|
118
117
|
@auth_identifier = @auth.gsub("current_", "")
|
119
118
|
end
|
120
119
|
|
120
|
+
# when in self auth, the object is the same as the authenticated object
|
121
|
+
if @auth && auth_identifier == @singular
|
122
|
+
@self_auth = true
|
123
|
+
end
|
124
|
+
|
121
125
|
if !@nest.nil?
|
122
126
|
@nested_args = @nest.split("/")
|
123
|
-
|
124
127
|
@nested_args_plural = {}
|
125
128
|
@nested_args.each do |a|
|
126
129
|
@nested_args_plural[a] = a + "s"
|
127
130
|
end
|
128
131
|
end
|
132
|
+
|
133
|
+
# the @object_owner will always be object that will 'own' the object
|
134
|
+
# for new and create
|
135
|
+
|
136
|
+
if @auth && ! @self_auth && @nested_args.none?
|
137
|
+
@object_owner_sym = @auth.gsub("current_", "").to_sym
|
138
|
+
@object_owner_eval = @auth
|
139
|
+
else
|
140
|
+
@object_owner_sym = @nested_args.last.to_sym
|
141
|
+
@object_owner_eval = "@#{@nested_args.last}"
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
# create the columns
|
147
|
+
auth_assoc_field = auth_assoc + "_id"
|
148
|
+
|
149
|
+
ownership_field = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})").name.to_s + "_id"
|
150
|
+
|
151
|
+
|
152
|
+
exclude_fields = [auth_assoc_field.to_sym, ownership_field.to_sym, :id, :created_at, :updated_at, :encrypted_password, :reset_password_token,
|
153
|
+
:reset_password_sent_at, :remember_created_at, :confirmation_token, :confirmed_at,
|
154
|
+
:confirmation_sent_at, :unconfirmed_email]
|
155
|
+
begin
|
156
|
+
@columns = object.columns.map(&:name).map(&:to_sym).reject{|field| exclude_fields.include?(field) }
|
157
|
+
rescue StandardError => e
|
158
|
+
puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
|
159
|
+
exit
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
|
129
164
|
end
|
130
165
|
|
131
166
|
def formats
|
@@ -141,6 +176,9 @@ module CommonCore
|
|
141
176
|
|
142
177
|
unless @specs_only
|
143
178
|
template "controller.rb", File.join("app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
|
179
|
+
if @namespace && defined?(controller_descends_from) == nil
|
180
|
+
template "base_controller.rb", File.join("app/controllers#{namespace_with_dash}", "base_controller.rb")
|
181
|
+
end
|
144
182
|
end
|
145
183
|
|
146
184
|
unless @no_specs
|
@@ -223,6 +261,14 @@ module CommonCore
|
|
223
261
|
end
|
224
262
|
|
225
263
|
|
264
|
+
def path_helper_full
|
265
|
+
"#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
|
266
|
+
end
|
267
|
+
|
268
|
+
def path_helper_args
|
269
|
+
[(@nested_args if @nested_args.any?).collect{|a| "@#{a}"} , singular].join(",")
|
270
|
+
end
|
271
|
+
|
226
272
|
def path_helper_singular
|
227
273
|
"#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{singular}_path"
|
228
274
|
end
|
@@ -252,7 +298,7 @@ module CommonCore
|
|
252
298
|
end
|
253
299
|
|
254
300
|
def nested_arity_for_path
|
255
|
-
@nested_args.join(", ") #metaprgramming into arity for the Rails path helper
|
301
|
+
[@nested_args[0..-1].collect{|a| "@#{a}"}].join(", ") #metaprgramming into arity for the Rails path helper
|
256
302
|
end
|
257
303
|
|
258
304
|
def object_scope
|
@@ -270,7 +316,9 @@ module CommonCore
|
|
270
316
|
|
271
317
|
def all_objects_root
|
272
318
|
if @auth
|
273
|
-
if @
|
319
|
+
if @self_auth
|
320
|
+
@singular_class + ".where(id: #{@auth}.id)"
|
321
|
+
elsif @nested_args.none?
|
274
322
|
@auth + ".#{plural}"
|
275
323
|
else
|
276
324
|
"@" + @nested_args.last + ".#{plural}"
|
@@ -285,8 +333,12 @@ module CommonCore
|
|
285
333
|
end
|
286
334
|
|
287
335
|
def all_objects_variable
|
336
|
+
|
288
337
|
# needs the authenticated root user
|
289
|
-
"#{@auth}.#{ @nested_args.map{|a| "#{@nested_args_plural[a]}.find(@#{a})"}.join('.') + "." if @nested_args.any?}#{plural}"
|
338
|
+
# "#{@auth}.#{ @nested_args.map{|a| "#{@nested_args_plural[a]}.find(@#{a})"}.join('.') + "." if @nested_args.any?}#{plural}"
|
339
|
+
|
340
|
+
all_objects_root + ".page(params[:page])"
|
341
|
+
|
290
342
|
end
|
291
343
|
|
292
344
|
def auth_object
|
@@ -344,15 +396,6 @@ module CommonCore
|
|
344
396
|
:erb
|
345
397
|
end
|
346
398
|
|
347
|
-
|
348
|
-
def create_merge_params
|
349
|
-
if @auth
|
350
|
-
"#{@auth_identifier}: #{@auth}"
|
351
|
-
else
|
352
|
-
""
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
399
|
def model_has_strings?
|
357
400
|
false
|
358
401
|
end
|
@@ -383,6 +426,7 @@ module CommonCore
|
|
383
426
|
puts "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
384
427
|
exit
|
385
428
|
end
|
429
|
+
assoc_class_name = eval("#{singular_class}.reflect_on_association(:#{assoc_name})").class_name
|
386
430
|
|
387
431
|
if assoc.active_record.column_names.include?("name")
|
388
432
|
display_column = "name"
|
@@ -394,11 +438,14 @@ module CommonCore
|
|
394
438
|
display_column = "display_name"
|
395
439
|
elsif assoc.active_record.column_names.include?("email")
|
396
440
|
display_column = "email"
|
441
|
+
else
|
442
|
+
puts "Can't find a display_column on {singular_class} object"
|
397
443
|
end
|
398
444
|
|
445
|
+
|
399
446
|
".row
|
400
447
|
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
|
401
|
-
= f.collection_select(:#{col.to_s}, #{
|
448
|
+
= f.collection_select(:#{col.to_s}, #{assoc_class_name}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
|
402
449
|
%label.small.form-text.text-muted
|
403
450
|
#{col.to_s.humanize}"
|
404
451
|
|
@@ -411,7 +458,7 @@ module CommonCore
|
|
411
458
|
end
|
412
459
|
when :string
|
413
460
|
limit ||= 256
|
414
|
-
if limit
|
461
|
+
if limit <= 256
|
415
462
|
field_output(col, nil, limit)
|
416
463
|
else
|
417
464
|
text_area_output(col, limit)
|
@@ -419,7 +466,7 @@ module CommonCore
|
|
419
466
|
|
420
467
|
when :text
|
421
468
|
limit ||= 256
|
422
|
-
if limit
|
469
|
+
if limit <= 256
|
423
470
|
field_output(col, nil, limit)
|
424
471
|
else
|
425
472
|
text_area_output(col, limit)
|
@@ -428,16 +475,27 @@ module CommonCore
|
|
428
475
|
when :datetime
|
429
476
|
".row
|
430
477
|
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
431
|
-
= datetime_field_localized(f, :#{col.to_s},
|
478
|
+
= datetime_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
|
432
479
|
when :date
|
433
480
|
".row
|
434
481
|
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
435
|
-
= date_field_localized(f, :#{col.to_s},
|
482
|
+
= date_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
|
436
483
|
when :time
|
437
484
|
".row
|
438
485
|
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
439
|
-
= time_field_localized(f, :#{col.to_s},
|
486
|
+
= time_field_localized(f, :#{col.to_s}, #{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
|
487
|
+
when :boolean
|
488
|
+
".row
|
489
|
+
%div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
|
490
|
+
%span
|
491
|
+
#{col.to_s.humanize}
|
492
|
+
= f.radio_button(:#{col.to_s}, '0', checked: #{singular}.#{col.to_s} ? '' : 'checked')
|
493
|
+
= f.label(:#{col.to_s}, value: 'No', for: '#{singular}_#{col.to_s}_0')
|
494
|
+
|
495
|
+
= f.radio_button(:#{col.to_s}, '1', checked: #{singular}.#{col.to_s} ? 'checked' : '')
|
496
|
+
= f.label(:#{col.to_s}, value: 'Yes', for: '#{singular}_#{col.to_s}_1')
|
440
497
|
|
498
|
+
"
|
441
499
|
end
|
442
500
|
|
443
501
|
}.join("\n")
|
@@ -483,7 +541,7 @@ module CommonCore
|
|
483
541
|
end
|
484
542
|
|
485
543
|
" %td
|
486
|
-
= #{singular}.#{assoc.name.to_s}
|
544
|
+
= #{singular}.#{assoc.name.to_s}.try(:#{display_column}) || '<span class=\"content alert-danger\">MISSING</span>'.html_safe"
|
487
545
|
|
488
546
|
else
|
489
547
|
" %td
|
@@ -520,7 +578,16 @@ module CommonCore
|
|
520
578
|
%span.alert-danger
|
521
579
|
MISSING
|
522
580
|
"
|
523
|
-
|
581
|
+
when :boolean
|
582
|
+
" %td
|
583
|
+
- if #{singular}.#{col}.nil?
|
584
|
+
%span.alert-danger
|
585
|
+
MISSING
|
586
|
+
- elsif #{singular}.#{col}
|
587
|
+
YES
|
588
|
+
- else
|
589
|
+
NO
|
590
|
+
"
|
524
591
|
end
|
525
592
|
}.join("\n")
|
526
593
|
return res
|
@@ -536,6 +603,17 @@ module CommonCore
|
|
536
603
|
end
|
537
604
|
|
538
605
|
|
606
|
+
def destroy_action
|
607
|
+
return false if @self_auth
|
608
|
+
return !@no_delete
|
609
|
+
end
|
610
|
+
|
611
|
+
def create_action
|
612
|
+
return false if @self_auth
|
613
|
+
return !@no_create
|
614
|
+
end
|
615
|
+
|
616
|
+
|
539
617
|
private # thor does something fancy like sending the class all of its own methods during some strange run sequence
|
540
618
|
# does not like public methods
|
541
619
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
<%= all_line_fields %>
|
2
2
|
%td
|
3
|
-
|
3
|
+
<% if destroy_action %>
|
4
|
+
= link_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe, <%= path_helper_full %>(<%= path_helper_args %>), remote: true, method: :delete, data: {confirm: 'Are you sure?'}, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary "
|
5
|
+
<% end %>
|
4
6
|
|
5
|
-
= link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%=
|
7
|
+
= link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_full %>(<%= path_helper_args %>), remote: true , disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary "
|
@@ -1,9 +1,9 @@
|
|
1
1
|
|
2
|
+
<% if create_action %>
|
2
3
|
= link_to "New <%= singular.gsub('_',' ') %>", new_<%= path_helper_singular %>(<%= nested_arity_for_path %>), disable_with: "Loading...", remote: true, class: "new-<%= singular %>-button btn btn-primary pull-right"
|
3
|
-
|
4
4
|
.clearfix
|
5
5
|
.new-<%= singular %>-form{style: "display: none; position: relative;"}
|
6
|
-
|
6
|
+
<% end %>
|
7
7
|
|
8
8
|
|
9
9
|
%table.table.table-striped.<%= singular %>-table
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class <%= controller_class_name %> < <%= controller_descends_from %>
|
2
|
-
<% unless @auth_identifier
|
2
|
+
<% unless @auth_identifier == '' %>
|
3
3
|
before_action :authenticate_<%= auth_identifier %>!
|
4
4
|
|
5
5
|
<% end %>
|
@@ -7,6 +7,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
7
7
|
before_action :load_<%= arg %><% end %> <% end %>
|
8
8
|
before_action :load_<%= singular_name %>, only: [:show, :edit, :update, :destroy]
|
9
9
|
helper :common_core
|
10
|
+
include CommonCoreJs::ControllerHelpers
|
10
11
|
|
11
12
|
<% if any_nested? %><% nest_chain = [] %> <% @nested_args.each do |arg| %>
|
12
13
|
<% if nest_chain.empty?
|
@@ -19,28 +20,37 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
19
20
|
@<%= arg %> = <%= this_scope %>.find(params[:<%= arg %>_id])
|
20
21
|
end<% end %> <% end %>
|
21
22
|
|
23
|
+
|
24
|
+
<% if !@self_auth %>
|
22
25
|
def load_<%= singular_name %>
|
23
26
|
@<%= singular_name %> = <%= object_scope %>.find(params[:id])
|
24
27
|
end
|
28
|
+
<% else %>
|
29
|
+
def load_<%= singular_name %>
|
30
|
+
@<%= singular_name %> = <%= auth_object %>
|
31
|
+
end<% end %>
|
25
32
|
|
26
33
|
def index
|
34
|
+
<% if !@self_auth %>
|
27
35
|
@<%= plural_name %> = <%= object_scope %><% if model_has_strings? %>.where(<%=class_name %>.arel_table[:email].matches("%#{@__general_string}%"))<% end %>.page(params[:page])
|
28
|
-
|
36
|
+
<% else %>
|
37
|
+
@<%= plural_name %> = [<%= auth_object %>]
|
38
|
+
<% end %>
|
29
39
|
respond_to do |format|
|
30
40
|
format.js<% if @with_index %>
|
31
41
|
format.html {render 'all.haml'}<% end %>
|
32
42
|
end
|
33
43
|
end
|
34
44
|
|
35
|
-
def new
|
36
|
-
@<%= singular_name %> = <%= class_name %>.new(<%=
|
45
|
+
<% if create_action %> def new
|
46
|
+
@<%= singular_name %> = <%= class_name %>.new(<%= @object_owner_sym %>: <%= @object_owner_eval %>)
|
37
47
|
respond_to do |format|
|
38
48
|
format.js
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
42
52
|
def create
|
43
|
-
modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if
|
53
|
+
modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !@object_owner_sym.empty? %>.merge!(<%= @object_owner_sym %>: <%= @object_owner_eval %> )<% end %>, <%= @auth %>)
|
44
54
|
@<%=singular_name %> = <%=class_name %>.create(modified_params)
|
45
55
|
respond_to do |format|
|
46
56
|
if @<%= singular_name %>.save
|
@@ -49,7 +59,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
49
59
|
end
|
50
60
|
format.js
|
51
61
|
end
|
52
|
-
end
|
62
|
+
end<% end %>
|
53
63
|
|
54
64
|
def show
|
55
65
|
respond_to do |format|
|
@@ -65,14 +75,14 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
65
75
|
|
66
76
|
def update
|
67
77
|
respond_to do |format|
|
68
|
-
if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params ))
|
78
|
+
if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params, <%= @auth %> ))
|
69
79
|
flash[:alert] = "<%=singular_name.titlecase %> could not be saved"
|
70
80
|
end
|
71
81
|
format.js {}
|
72
82
|
end
|
73
83
|
end
|
74
84
|
|
75
|
-
|
85
|
+
<% if destroy_action %>def destroy
|
76
86
|
respond_to do |format|
|
77
87
|
begin
|
78
88
|
@<%=singular_name%>.destroy
|
@@ -81,7 +91,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
81
91
|
end
|
82
92
|
format.js {}
|
83
93
|
end
|
84
|
-
end
|
94
|
+
end<% end %>
|
85
95
|
|
86
96
|
def <%=singular_name%>_params
|
87
97
|
params.require(:<%=singular_name%>).permit( <%= @columns %> )
|
@@ -1 +1 @@
|
|
1
|
-
<%%= render partial: 'common/common_create', locals: {object: @<%= singular %>, singular: "<%= singular %>", plural: "<%= plural %>"} %>
|
1
|
+
<%%= render partial: 'common/common_create', locals: {object: @<%= singular %>, singular: "<%= singular %>", plural: "<%= plural %>"<%= ", " + nested_assignments if nested_assignments %>} %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: common_core_js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Fleetwood-Boldt
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- ".generators"
|
132
132
|
- ".gitignore"
|
133
133
|
- ".rakeTasks"
|
134
|
+
- FUNDING.yml
|
134
135
|
- Gemfile
|
135
136
|
- Gemfile.lock
|
136
137
|
- LICENSE
|
@@ -143,6 +144,7 @@ files:
|
|
143
144
|
- app/assets/stylesheets/common_core_js/common_core.scss
|
144
145
|
- app/controllers/common_core_js/application_controller.rb
|
145
146
|
- app/helpers/common_core_helper.rb
|
147
|
+
- app/helpers/common_core_js/controller_helper.rb
|
146
148
|
- app/jobs/common_core_js/application_job.rb
|
147
149
|
- app/mailers/common_core_js/application_mailer.rb
|
148
150
|
- app/models/common_core_js/application_record.rb
|
@@ -176,6 +178,7 @@ files:
|
|
176
178
|
- lib/generators/common_core/templates/_list.haml
|
177
179
|
- lib/generators/common_core/templates/_new.haml
|
178
180
|
- lib/generators/common_core/templates/all.haml
|
181
|
+
- lib/generators/common_core/templates/base_controller.rb
|
179
182
|
- lib/generators/common_core/templates/common_core.js
|
180
183
|
- lib/generators/common_core/templates/common_core.scss
|
181
184
|
- lib/generators/common_core/templates/controller.rb
|