common_core_js 0.3.3 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7e5ec56e4fffb8aab8840c9cc1aff9377d1291bd9b82fd91fe57841089d8b9e
4
- data.tar.gz: c688ccfbca5218fdc210ee199b87e5b61f32405179f41268d2776b086e22e58a
3
+ metadata.gz: 69b48d2b11f7087d3a842266d1c08df9da022bc7191dbc71f286431ac02112f0
4
+ data.tar.gz: cdc77c41c2dff7e393837fb1954fc0bd599083c2ce305e98416c097866d6c4a8
5
5
  SHA512:
6
- metadata.gz: 69bdb23d11a350e5f31b160840dc1f96abf8706a3716df9250e992e1e8cacbfd4b7d10d17be2103fc3f38c1064b178eec7cd2a445ead0c1c5e7269a59188560d
7
- data.tar.gz: 29d5aea167e7cfaba9861758a72c8ecc16883ec1b70d11294e45e4ef89377d5654c12a0dcfbcac4c0d3a1b8abdace463e68fc9ca39f9aedfccbc20b18e470f0a
6
+ metadata.gz: bceefae2fd396020f7225df73e9f74a4f6ea7d06b94250880c872e68c921b43ac1eb0b0f34805098fbab5ca877fe26d54dc152230d2990a9b58428ccf9f6e6ea
7
+ data.tar.gz: d40870c3538adc2a9d687d583e7b3821544eff497425bf00f712d6426945477d7ac0bc191072ef5befbe0f38b9b0eb1b28b81298719d6eec38a427c458299509
@@ -0,0 +1,4 @@
1
+ # repo: your_github_handle/foobar
2
+ # filename: FUNDING.YML
3
+
4
+ github: [jasonfb]
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
- = THE SALES PITCH:
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 autoamatically along with the controllers.
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
- = HOW EASY?
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
- = TO INSTALL
36
+ ## TO INSTALL
30
37
 
31
38
  - Add common_core_js to your Gemfile
32
39
 
@@ -1,5 +1,10 @@
1
- module CommonCoreJs
2
- module ApplicationHelper
1
+ module CommonCoreHelper
2
+
3
+ def timezonize(tz)
4
+ tz = tz.to_i
5
+ (tz >= 0 ? "+" : "-") + sprintf('%02d',tz.abs) + ":00"
6
+ end
7
+
3
8
 
4
9
  def datetime_field_localized(form_object, field_name, value, label, timezone = nil )
5
10
  res = form_object.label(label,
@@ -10,19 +15,20 @@ module CommonCoreJs
10
15
  type: 'datetime-local',
11
16
  value: date_to_current_timezone(value, timezone))
12
17
 
13
- res << human_timezone(Time.now, timezone)
18
+ res << timezonize(timezone)
14
19
  res
15
20
  end
16
21
 
17
22
 
18
23
  def date_field_localized(form_object, field_name, value, label, timezone = nil )
24
+
19
25
  res = form_object.label(label,
20
26
  field_name,
21
27
  class: 'small form-text text-muted')
22
28
 
23
29
  res << form_object.text_field(field_name, class: 'form-control',
24
30
  type: 'date',
25
- value: date_to_current_timezone(value, timezone))
31
+ value: value )
26
32
 
27
33
  res
28
34
  end
@@ -36,31 +42,24 @@ module CommonCoreJs
36
42
  type: 'time',
37
43
  value: date_to_current_timezone(value, timezone))
38
44
 
39
- res << human_timezone(Time.now, timezone)
45
+ res << timezonize(tz)
40
46
  res
41
47
  end
42
48
 
43
49
  def current_timezone
44
- if method(:current_user)
50
+ if controller.try(:current_timezone)
51
+ controller.current_timezone
52
+ elsif defined?(current_user)
45
53
  if current_user.try(:timezone)
46
- 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
47
55
  else
48
56
  Time.now.strftime("%z").to_i/100
49
57
  end
50
58
  else
51
- raise "no method current_user is available or it does not implement timezone; please implement/override the method current_timezone"
59
+ raise "no method current_user is available or it does not implement timezone; please implement/override the method current_timezone IN YOUR CONTROLLER"
52
60
  end
53
61
  end
54
62
 
55
- def human_timezone(time_string, timezone)
56
- time = time_string.in_time_zone(timezone)
57
-
58
- if time.zone.match?(/^\w/)
59
- time.zone
60
- else
61
- time.formatted_offset
62
- end
63
- end
64
63
 
65
64
  def date_to_current_timezone(date, timezone = nil)
66
65
  # if the timezone is nil, use the server date'
@@ -76,5 +75,4 @@ module CommonCoreJs
76
75
  return nil
77
76
  end
78
77
  end
79
- end
80
78
  end
@@ -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
@@ -1,4 +1,8 @@
1
1
  %td{style: "position: relative;", colspan: controller.default_colspan}
2
+ - if object.errors.any?
3
+ = render(partial: "#{controller.namespace}errors", locals: {resource: object})
4
+
5
+
2
6
  Editing
3
7
  - if object.try(:to_label)
4
8
  = object.to_label
@@ -1,6 +1,7 @@
1
1
  <% if object.errors.any? %>
2
2
  <% pass_through_locals ||= {} %>
3
- $(".<%= singular %>-table tr[data-id=<%= object.id %>][data-edit='true']").html("<%= j render(partial: '#{controller.namespace}errors', locals: {resource: object}) %><%= j render partial: 'edit', locals: {singular.to_sym => object, url: url, colspan: controller.default_colspan}.merge(pass_through_locals || {}) %>")
3
+ $(".<%= singular %>-table tr[data-id=<%= object.id %>][data-edit='true']").html("<%= j render partial: 'edit', locals: {singular.to_sym => object, url: url, colspan: controller.default_colspan}.merge(pass_through_locals || {}) %>")
4
+
4
5
  $(".flash-notices").html("<%= j render 'layouts/flash_notices' %>");
5
6
  <% else %>
6
7
  $(".<%= singular %>-table tr[data-id=<%= object.id %>]:not([data-edit='true'])").replaceWith("<%= j render partial: 'line', locals: {singular.to_sym => object } %>").fadeIn()
@@ -1,3 +1,3 @@
1
1
  module CommonCoreJs
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.8'
3
3
  end
@@ -13,7 +13,7 @@ module CommonCore
13
13
  end
14
14
 
15
15
  ".row
16
- .form-group.col-md-4
16
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
17
17
  = f.text_area :#{col.to_s}, class: 'form-control', cols: 40, rows: '#{lines}'
18
18
  %label.form-text
19
19
  #{col.to_s.humanize}\n"
@@ -23,7 +23,7 @@ module CommonCore
23
23
 
24
24
  def field_output(col, type = nil, width)
25
25
  ".row
26
- .form-group.col-md-4
26
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
27
27
  = f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, size: #{width}, class: 'form-control', type: '#{type}'
28
28
  %label.form-text
29
29
  #{col.to_s.humanize}\n"
@@ -86,15 +86,19 @@ module CommonCore
86
86
  auth_assoc = @auth.gsub("current_","")
87
87
  auth_assoc_field = auth_assoc + "_id"
88
88
 
89
-
89
+ exclude_fields = [auth_assoc_field.to_sym, :id, :created_at, :updated_at, :encrypted_password, :reset_password_token,
90
+ :reset_password_sent_at, :remember_created_at, :confirmation_token, :confirmed_at,
91
+ :confirmation_sent_at, :unconfirmed_email]
90
92
  begin
91
- @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| field==:updated_at ||
92
- field==:created_at || field==:id || field == auth_assoc_field.to_sym }
93
+ @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| exclude_fields.include?(field) }
93
94
  rescue StandardError => e
94
95
  puts "Ooops... it looks like is an object for #{class_name}. Please create the database table with fields first. "
95
96
  exit
96
97
  end
97
98
 
99
+ @no_delete = false
100
+ @no_create = false
101
+
98
102
  flags = meta_args[1]
99
103
  flags.each do |f|
100
104
  case (f)
@@ -106,6 +110,10 @@ module CommonCore
106
110
  @specs_only = true
107
111
  when "--no-specs"
108
112
  @no_specs = true
113
+ when "--no-delete"
114
+ @no_delete = true
115
+ when "--no-create"
116
+ @no_create = true
109
117
  end
110
118
  end
111
119
 
@@ -118,6 +126,11 @@ module CommonCore
118
126
  @auth_identifier = @auth.gsub("current_", "")
119
127
  end
120
128
 
129
+
130
+ if @auth && auth_identifier == @singular
131
+ @self_auth = true
132
+ end
133
+
121
134
  if !@nest.nil?
122
135
  @nested_args = @nest.split("/")
123
136
 
@@ -141,6 +154,9 @@ module CommonCore
141
154
 
142
155
  unless @specs_only
143
156
  template "controller.rb", File.join("app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
157
+ if @namespace && defined?(controller_descends_from) == nil
158
+ template "base_controller.rb", File.join("app/controllers#{namespace_with_dash}", "base_controller.rb")
159
+ end
144
160
  end
145
161
 
146
162
  unless @no_specs
@@ -270,7 +286,9 @@ module CommonCore
270
286
 
271
287
  def all_objects_root
272
288
  if @auth
273
- if @nested_args.none?
289
+ if @self_auth
290
+ @singular_class + ".where(id: #{@auth}.id)"
291
+ elsif @nested_args.none?
274
292
  @auth + ".#{plural}"
275
293
  else
276
294
  "@" + @nested_args.last + ".#{plural}"
@@ -285,8 +303,12 @@ module CommonCore
285
303
  end
286
304
 
287
305
  def all_objects_variable
306
+
288
307
  # needs the authenticated root user
289
- "#{@auth}.#{ @nested_args.map{|a| "#{@nested_args_plural[a]}.find(@#{a})"}.join('.') + "." if @nested_args.any?}#{plural}"
308
+ # "#{@auth}.#{ @nested_args.map{|a| "#{@nested_args_plural[a]}.find(@#{a})"}.join('.') + "." if @nested_args.any?}#{plural}"
309
+
310
+ all_objects_root + ".page(params[:page])"
311
+
290
312
  end
291
313
 
292
314
  def auth_object
@@ -346,7 +368,7 @@ module CommonCore
346
368
 
347
369
 
348
370
  def create_merge_params
349
- if @auth
371
+ if @auth && ! @self_auth
350
372
  "#{@auth_identifier}: #{@auth}"
351
373
  else
352
374
  ""
@@ -394,32 +416,34 @@ module CommonCore
394
416
  display_column = "display_name"
395
417
  elsif assoc.active_record.column_names.include?("email")
396
418
  display_column = "email"
419
+ else
420
+ puts "Can't find a display_column on {singular_class} object"
397
421
  end
398
422
 
399
423
  ".row
400
- .form-group.col-md-4
424
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
401
425
  = f.collection_select(:#{col.to_s}, #{assoc_name.titleize}.all, :id, :#{display_column}, {prompt: true, selected: @#{singular}.#{col.to_s} }, class: 'form-control')
402
426
  %label.small.form-text.text-muted
403
427
  #{col.to_s.humanize}"
404
428
 
405
429
  else
406
430
  ".row
407
- .form-group.col-md-4
431
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
408
432
  = f.text_field :#{col.to_s}, value: @#{singular}.#{col.to_s}, class: 'form-control', size: 4, type: 'number'
409
433
  %label.form-text
410
434
  #{col.to_s.humanize}\n"
411
435
  end
412
436
  when :string
413
- limit ||= 40
414
- if limit < 50
437
+ limit ||= 256
438
+ if limit <= 256
415
439
  field_output(col, nil, limit)
416
440
  else
417
441
  text_area_output(col, limit)
418
442
  end
419
443
 
420
444
  when :text
421
- limit ||= 40
422
- if limit < 50
445
+ limit ||= 256
446
+ if limit <= 256
423
447
  field_output(col, nil, limit)
424
448
  else
425
449
  text_area_output(col, limit)
@@ -427,16 +451,16 @@ module CommonCore
427
451
 
428
452
  when :datetime
429
453
  ".row
430
- .form-group.col-md-4
431
- = datetime_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth}.timezone)"
454
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
455
+ = datetime_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
432
456
  when :date
433
457
  ".row
434
- .form-group.col-md-4
435
- = date_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth}.timezone)"
458
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
459
+ = date_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
436
460
  when :time
437
461
  ".row
438
- .form-group.col-md-4
439
- = time_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth}.timezone)"
462
+ %div{class: \"form-group col-md-4 \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{col.to_s})}\"}
463
+ = time_field_localized(f, :#{col.to_s}, @#{singular}.#{col.to_s}, '#{col.to_s.humanize}', #{@auth ? @auth+'.timezone' : 'nil'})"
440
464
 
441
465
  end
442
466
 
@@ -499,7 +523,7 @@ module CommonCore
499
523
  when :datetime
500
524
  " %td
501
525
  - unless #{singular}.#{col}.nil?
502
- = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + human_timezone(Time.now, current_timezone)
526
+ = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%m/%d/%Y @ %l:%M %p ') + timezonize(current_timezone)
503
527
  - else
504
528
  %span.alert-danger
505
529
  MISSING
@@ -510,13 +534,15 @@ module CommonCore
510
534
  = #{singular}.#{col}
511
535
  - else
512
536
  %span.alert-danger
537
+ MISSING
513
538
  "
514
539
  when :time
515
540
  " %td
516
541
  - unless #{singular}.#{col}.nil?
517
- = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + human_timezone(Time.now, current_timezone)
542
+ = #{singular}.#{col}.in_time_zone(current_timezone).strftime('%l:%M %p ') + timezonize(current_timezone)
518
543
  - else
519
544
  %span.alert-danger
545
+ MISSING
520
546
  "
521
547
 
522
548
  end
@@ -525,6 +551,25 @@ module CommonCore
525
551
  end
526
552
 
527
553
 
554
+ def controller_descends_from
555
+ if defined?(@namespace.titlecase + "::BaseController")
556
+ @namespace.titlecase + "::BaseController"
557
+ else
558
+ "ApplicationController"
559
+ end
560
+ end
561
+
562
+
563
+ def destroy_action
564
+ return false if @self_auth
565
+ return !@no_delete
566
+ end
567
+
568
+ def create_action
569
+ return false if @self_auth
570
+ return !@no_create
571
+ end
572
+
528
573
 
529
574
  private # thor does something fancy like sending the class all of its own methods during some strange run sequence
530
575
  # does not like public methods
@@ -1,3 +1,7 @@
1
1
  <%= all_line_fields %>
2
2
  %td
3
- = link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_singular %>(<%= singular %>), remote: true , disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary pull-right "
3
+ <% if destroy_action %>
4
+ = link_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe, <%= path_helper_singular %>(<%= singular %>), remote: true, method: :delete, data: {confirm: 'Are you sure?'}, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary "
5
+ <% end %>
6
+ &nbsp;
7
+ = link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_singular %>(<%= singular %>), 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,4 +1,5 @@
1
1
  .container-fluid
2
2
  .row
3
3
  .col-md-12
4
- = render partial: "<%= namespace_with_trailing_dash %><%= plural %>/list", locals: {<%= plural %>: <%= all_objects_root %>.order("created_at DESC").page(1)}
4
+ .<%= singular %>-list
5
+ = render partial: "<%= namespace_with_trailing_dash %><%= plural %>/list", locals: {<%= plural %>: <%= all_objects_root %>.order("created_at DESC").page(1)}
@@ -0,0 +1,3 @@
1
+ class <%= controller_descends_from %> < ApplicationController
2
+ end
3
+
@@ -1,9 +1,9 @@
1
1
 
2
2
  require("jquery")
3
- console.log("loading common core...")
3
+ // console.log("loading common core...")
4
4
 
5
- require("jstimezonedetect/dist/jstz.min")
6
- var JSTZ = require('jstimezonedetect');
5
+ // require("jstimezonedetect/dist/jstz.min")
6
+ // var JSTZ = require('jstimezonedetect');
7
7
 
8
8
 
9
9
 
@@ -0,0 +1,5 @@
1
+ [data-role='close-button'] {
2
+ position: absolute;
3
+ top: 0;
4
+ right: 0;
5
+ }
@@ -1,4 +1,4 @@
1
- class <%= controller_class_name %> < ApplicationController
1
+ class <%= controller_class_name %> < <%= controller_descends_from %>
2
2
  <% unless @auth_identifier.nil? %>
3
3
  before_action :authenticate_<%= auth_identifier %>!
4
4
 
@@ -6,7 +6,8 @@ class <%= controller_class_name %> < ApplicationController
6
6
  <% if any_nested? %> <% @nested_args.each do |arg| %>
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,21 +20,29 @@ class <%= controller_class_name %> < ApplicationController
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
25
- include CommonCoreJs::ControllerHelpers
28
+ <% else %>
29
+ def load_<%= singular_name %>
30
+ @<%= singular_name %> = <%= auth_object %>
31
+ end<% end %>
26
32
 
27
33
  def index
34
+ <% if !@self_auth %>
28
35
  @<%= plural_name %> = <%= object_scope %><% if model_has_strings? %>.where(<%=class_name %>.arel_table[:email].matches("%#{@__general_string}%"))<% end %>.page(params[:page])
29
-
36
+ <% else %>
37
+ @<%= plural_name %> = [<%= auth_object %>]
38
+ <% end %>
30
39
  respond_to do |format|
31
40
  format.js<% if @with_index %>
32
41
  format.html {render 'all.haml'}<% end %>
33
42
  end
34
43
  end
35
44
 
36
- def new
45
+ <% if create_action %> def new
37
46
  @<%= singular_name %> = <%= class_name %>.new(<%= create_merge_params %>)
38
47
  respond_to do |format|
39
48
  format.js
@@ -41,7 +50,7 @@ class <%= controller_class_name %> < ApplicationController
41
50
  end
42
51
 
43
52
  def create
44
- modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !create_merge_params.empty? %>.merge!(<%= create_merge_params %><%end%> ), <%=@auth%>)
53
+ modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !create_merge_params.empty? %>.merge!(<%= create_merge_params %>)<% end %> <%= @auth ? ",#{@auth}" : "" %>)
45
54
  @<%=singular_name %> = <%=class_name %>.create(modified_params)
46
55
  respond_to do |format|
47
56
  if @<%= singular_name %>.save
@@ -50,7 +59,7 @@ class <%= controller_class_name %> < ApplicationController
50
59
  end
51
60
  format.js
52
61
  end
53
- end
62
+ end<% end %>
54
63
 
55
64
  def show
56
65
  respond_to do |format|
@@ -66,14 +75,14 @@ class <%= controller_class_name %> < ApplicationController
66
75
 
67
76
  def update
68
77
  respond_to do |format|
69
- if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params, <%=@auth%> ))
78
+ if !@<%=singular_name %>.update(modify_date_inputs_on_params(<%= singular %>_params, <%= @auth ? @auth : "nil" %> ))
70
79
  flash[:alert] = "<%=singular_name.titlecase %> could not be saved"
71
80
  end
72
81
  format.js {}
73
82
  end
74
83
  end
75
84
 
76
- def destroy
85
+ <% if destroy_action %>def destroy
77
86
  respond_to do |format|
78
87
  begin
79
88
  @<%=singular_name%>.destroy
@@ -82,7 +91,7 @@ class <%= controller_class_name %> < ApplicationController
82
91
  end
83
92
  format.js {}
84
93
  end
85
- end
94
+ end<% end %>
86
95
 
87
96
  def <%=singular_name%>_params
88
97
  params.require(:<%=singular_name%>).permit( <%= @columns %> )
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.3.3
4
+ version: 0.3.8
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
@@ -142,7 +143,8 @@ files:
142
143
  - app/assets/stylesheets/common_core_js/application.css
143
144
  - app/assets/stylesheets/common_core_js/common_core.scss
144
145
  - app/controllers/common_core_js/application_controller.rb
145
- - app/helpers/common_core_js/application_helper.rb
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