From 6548a49ac0f760f2ce787af2e916a66dde7533f3 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 11:47:42 -0500 Subject: [PATCH 01/47] API golden five --- .../draft/resource/resource_generator.rb | 34 +++--- .../templates/controllers/controller.rb | 104 ++++++++++++------ 2 files changed, 91 insertions(+), 47 deletions(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 7d49da2a..6334de25 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -30,13 +30,13 @@ def generate_model end def create_root_folder - empty_directory File.join("app/views", "#{singular_table_name}_templates") + empty_directory File.join("app/views", "#{plural_table_name}") end def generate_view_files available_views.each do |view| filename = view_filename_with_extensions(view) - template filename, File.join("app/views", "#{singular_table_name}_templates", File.basename(options[:new_form_name].presence || filename)) + template filename, File.join("app/views", "#{plural_table_name}", File.basename(options[:new_form_name].presence || filename)) end end @@ -46,7 +46,7 @@ def generate_routes if read_only? read_only_routes else - golden_seven_routes + golden_five_routes end end @@ -61,7 +61,7 @@ def generate_specs private - def golden_seven_routes + def golden_five_routes log :route, "RESTful routes" route <<-RUBY.gsub(/^ /, "") @@ -69,19 +69,21 @@ def golden_seven_routes # Routes for the #{singular_table_name.humanize} resource: # CREATE - get("/#{plural_table_name}/new", { :controller => "#{plural_table_name}", :action => "new_form" }) + match("/post_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create", :via => "post"}) + #{skip_post? ? "get" : "post"}("/create_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create_row" }) - + # READ - get("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index" }) - get("/#{plural_table_name}/:id_to_display", { :controller => "#{plural_table_name}", :action => "show" }) - + match("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index", :via => "get"}) + + match("/#{plural_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "show", :via => "get"}) + # UPDATE - get("/#{plural_table_name}/:prefill_with_id/edit", { :controller => "#{plural_table_name}", :action => "edit_form" }) + match("/patch_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "update", :via => "post"}) #{skip_post? ? "get" : "post"}("/update_#{singular_table_name}/:id_to_modify", { :controller => "#{plural_table_name}", :action => "update_row" }) - + # DELETE - get("/delete_#{singular_table_name}/:id_to_remove", { :controller => "#{plural_table_name}", :action => "destroy_row" }) + match("/delete_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "destroy", :via => "get"}) #------------------------------ RUBY @@ -95,9 +97,9 @@ def read_only_routes # Routes for the #{singular_table_name.humanize} resource: # READ - get("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index" }) - get("/#{plural_table_name}/:id_to_display", { :controller => "#{plural_table_name}", :action => "show" }) - + match("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index", :via => "get"}) + match("/#{plural_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "show", :via => "get"}) + #------------------------------ RUBY end @@ -158,7 +160,7 @@ def available_views elsif only_new_form? %w(association_new_form) else - %w(index new_form new_form_with_errors edit_form edit_form_with_errors show) + %w(index show) end end diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 5f930053..1e809d3e 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -1,34 +1,53 @@ class <%= plural_table_name.camelize %>Controller < ApplicationController def index @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all - - render("<%= singular_table_name.underscore %>_templates/index.html.erb") + + respond_to do |format| + format.json do + render({ :json => @<%= plural_table_name.underscore %>.as_json }) + end + + format.html do + render({ :template => "<%= plural_table_name.underscore %>/index.html.erb" }) + end + end end def show - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_display")) - - render("<%= singular_table_name.underscore %>_templates/show.html.erb") - end + the_id = params.fetch(:rt_<%= singular_table_name %>_id) + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({:id => the_id }).first - def new_form - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new + respond_to do |format| + format.json do + render({ :json => @<%= singular_table_name.underscore %>.as_json }) + end - render("<%= singular_table_name.underscore %>_templates/new_form.html.erb") + format.html do + render({ :template => "<%= plural_table_name.underscore %>/show.html.erb" }) + end + end end - def create_row + def create @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new <% attributes.each do |attribute| -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>") + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>", nil) <% end -%> <% unless skip_validation_alerts? -%> if @<%= singular_table_name.underscore %>.valid? @<%= singular_table_name.underscore %>.save - - redirect_back(:fallback_location => "/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> created successfully.") + respond_to do |format| + format.json do + render({ :json => @<%= singular_table_name.underscore %>.as_json }) + end + + format.html do + redirect_back({ :fallback_location => "/<%= plural_table_name.underscore %>/<%= singular_table_name %>", :notice => "<%= singular_table_name.humanize %> created successfully."}) + end + end + redirect_back(:fallback_location => "/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> created successfully."}) else render("<%= singular_table_name.underscore %>_templates/new_form_with_errors.html.erb") end @@ -45,26 +64,35 @@ def create_row <% end -%> end - def edit_form - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("prefill_with_id")) - - render("<%= singular_table_name.underscore %>_templates/edit_form.html.erb") - end - - def update_row - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_modify")) + def update + the_id = params.fetch(:rt_<%= singular_table_name %>_id) + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where(:id => the_id).at(0) <% attributes.each do |attribute| -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>") + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch(:<%= attribute.column_name %>, @<%= singular_table_name.underscore %><.%= attribute.column_name %>) <% end -%> <% unless skip_validation_alerts? -%> if @<%= singular_table_name.underscore %>.valid? @<%= singular_table_name.underscore %>.save - - redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.") + respond_to do |format| + format.json do + render({ :json => @<%= singular_table_name.underscore %>.as_json }) + end + + format.html do + redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", {:notice => "<%= singular_table_name.humanize %> updated successfully."}) + end else - render("<%= singular_table_name.underscore %>_templates/edit_form_with_errors.html.erb") + # render("<%= singular_table_name.underscore %>_templates/edit_form_with_errors.html.erb") + respond_to do |format| + format.json do + render({ :json => @<%= singular_table_name.underscore %>.as_json }) + end + + format.html do + render({ :template => "<%= plural_table_name.underscore %>/show.html.erb" }) + end end <% else -%> @<%= singular_table_name.underscore %>.save @@ -72,24 +100,38 @@ def update_row <% unless skip_redirect? -%> redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}") <% else -%> - render("<%= singular_table_name.underscore %>_templates/update_row.html.erb") -<% end -%> + respond_to do |format| + format.json do + render({ :json => @<%= singular_table_name.underscore %>.as_json }) + end + + format.html do + render({ :template => "<%= plural_table_name.underscore %>/show.html.erb" }) + end<% end -%> <% end -%> end - def destroy_row - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("id_to_remove")) + def destroy + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("rt_<%= singular_table_name %>_id")) @<%= singular_table_name.underscore %>.destroy <% unless skip_validation_alerts? -%> - redirect_to("/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.") + redirect_to("/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> deleted successfully."}) <% else -%> <% unless skip_redirect? -%> redirect_to("/<%= @plural_table_name.underscore %>") <% else -%> @remaining_count = <%= class_name.singularize %>.count - + + respond_to do |format| + format.json do + render({ :json => @<%= singular_table_name.underscore %>.as_json }) + end + + format.html do + redirect_to("/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> deleted successfully."}) + end render("<%= singular_table_name.underscore %>_templates/destroy_row.html.erb") <% end -%> <% end -%> From e10279fd2f7ed117d7c5164c268e738c24fe957b Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 12:06:08 -0500 Subject: [PATCH 02/47] wip --- .../draft/resource/resource_generator.rb | 2 +- .../templates/controllers/controller.rb | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 6334de25..ba89f81e 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -71,7 +71,7 @@ def golden_five_routes # CREATE match("/post_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create", :via => "post"}) - #{skip_post? ? "get" : "post"}("/create_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create_row" }) + #{skip_post? ? "get" : "post"}#("/create_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create_row" }) # READ match("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index", :via => "get"}) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 1e809d3e..e15289d3 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -32,7 +32,7 @@ def create @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new <% attributes.each do |attribute| -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>", nil) + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch(:<%= attribute.column_name %>, nil) <% end -%> <% unless skip_validation_alerts? -%> @@ -44,12 +44,20 @@ def create end format.html do - redirect_back({ :fallback_location => "/<%= plural_table_name.underscore %>/<%= singular_table_name %>", :notice => "<%= singular_table_name.humanize %> created successfully."}) + redirect_back({ :fallback_location => "/<%= plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> created successfully."}) end end - redirect_back(:fallback_location => "/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> created successfully."}) + redirect_back({ :fallback_location => "/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> created successfully."}) else - render("<%= singular_table_name.underscore %>_templates/new_form_with_errors.html.erb") + respond_to do |format| + format.json do + render({ :json => @<%= singular_table_name.underscore %>.as_json }) + end + + format.html do + redirect_back({ :fallback_location => "/<%= plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> failed to create successfully."}) + end + end end <% else -%> @<%= singular_table_name.underscore %>.save @@ -69,7 +77,7 @@ def update @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where(:id => the_id).at(0) <% attributes.each do |attribute| -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch(:<%= attribute.column_name %>, @<%= singular_table_name.underscore %><.%= attribute.column_name %>) + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch(:<%= attribute.column_name %>, @<%= singular_table_name.underscore %>.<%= attribute.column_name %>) <% end -%> <% unless skip_validation_alerts? -%> @@ -84,7 +92,7 @@ def update redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", {:notice => "<%= singular_table_name.humanize %> updated successfully."}) end else - # render("<%= singular_table_name.underscore %>_templates/edit_form_with_errors.html.erb") + # render({:template => "/<%= @plural_table_name.underscore %>/edit_form_with_errors.html.erb"}) respond_to do |format| format.json do render({ :json => @<%= singular_table_name.underscore %>.as_json }) @@ -112,12 +120,20 @@ def update end def destroy - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params.fetch("rt_<%= singular_table_name %>_id")) + the_id = params.fetch(:rt_<%= singular_table_name %>_id) + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).first @<%= singular_table_name.underscore %>.destroy <% unless skip_validation_alerts? -%> - redirect_to("/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> deleted successfully."}) + respond_to do |format| + format.json do + render({ :json => @<%= singular_table_name.underscore %>.as_json }) + end + + format.html do + redirect_to("/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> deleted successfully."}) + end <% else -%> <% unless skip_redirect? -%> redirect_to("/<%= @plural_table_name.underscore %>") From 3905fa8eb793a5958cf9e76a75d622744a4bc62f Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 14:41:29 -0500 Subject: [PATCH 03/47] wip --- lib/generators/draft/resource/resource_generator.rb | 10 ++++------ .../draft/resource/templates/controllers/controller.rb | 4 ++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index ba89f81e..7a6434d6 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -69,18 +69,16 @@ def golden_five_routes # Routes for the #{singular_table_name.humanize} resource: # CREATE - match("/post_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create", :via => "post"}) - - #{skip_post? ? "get" : "post"}#("/create_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create_row" }) - + match("/post_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create", :via => "#{skip_post? ? "get" : "post"}"}) + # READ match("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index", :via => "get"}) match("/#{plural_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "show", :via => "get"}) # UPDATE - match("/patch_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "update", :via => "post"}) - #{skip_post? ? "get" : "post"}("/update_#{singular_table_name}/:id_to_modify", { :controller => "#{plural_table_name}", :action => "update_row" }) + + match("/patch_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "update", :via => "#{skip_post? ? "get" : "post"}"}) # DELETE match("/delete_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "destroy", :via => "get"}) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index e15289d3..4614548f 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -91,6 +91,7 @@ def update format.html do redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", {:notice => "<%= singular_table_name.humanize %> updated successfully."}) end + end else # render({:template => "/<%= @plural_table_name.underscore %>/edit_form_with_errors.html.erb"}) respond_to do |format| @@ -101,6 +102,7 @@ def update format.html do render({ :template => "<%= plural_table_name.underscore %>/show.html.erb" }) end + end end <% else -%> @<%= singular_table_name.underscore %>.save @@ -134,6 +136,7 @@ def destroy format.html do redirect_to("/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> deleted successfully."}) end + end <% else -%> <% unless skip_redirect? -%> redirect_to("/<%= @plural_table_name.underscore %>") @@ -148,6 +151,7 @@ def destroy format.html do redirect_to("/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> deleted successfully."}) end + end render("<%= singular_table_name.underscore %>_templates/destroy_row.html.erb") <% end -%> <% end -%> From 4a26835eb349211833ea6ee78e3bfeafa844100f Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 14:56:34 -0500 Subject: [PATCH 04/47] wip --- .../resource/templates/views/index.html.erb | 71 +++++++++++++++++- .../resource/templates/views/show.html.erb | 73 ++++++++++++++++++- 2 files changed, 138 insertions(+), 6 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 2dea0e2f..89cb089d 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -1,12 +1,77 @@

- All <%= plural_table_name.humanize.downcase %> + List of all <%= plural_table_name.humanize.downcase %>

- +

Add a new <%= singular_table_name.humanize.downcase %> - +

+ +
+ + <% if with_sentinels? -%> + + <% end -%> +
method="post"<% end -%>> + <% if with_sentinels? -%> + + <% end -%> + + <% attributes.each do |attribute| -%> + <% if with_sentinels? -%> + + <% end -%> + <% if attribute.field_type == :check_box -%> +
+ + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> + +
+ <% else -%> +
+ + + <% if attribute.field_type == :text_area -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> + <% else -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> + <% end -%> +
+ <% if with_sentinels? -%> + + <% end -%> + <% end -%> + + <% end -%> + +
+ +
diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 91b2cc1b..485c2d50 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -15,9 +15,7 @@ <% end -%> <% if with_sentinels? -%> @@ -37,7 +35,76 @@ <% end -%> <% end -%> +
+

+ Edit <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %> +

+ +
+ + <% if with_sentinels? -%> + + <% end -%> +
method="post"<% end -%>> + <% if with_sentinels? -%> + + <% end -%> + <% attributes.each do |attribute| -%> + <% if with_sentinels? -%> + + <% end -%> + <% if attribute.field_type == :check_box -%> +
+ + <% if with_sentinels? -%> + + <% end -%> + .<%= attribute.column_name %> %>> + <% if with_sentinels? -%> + + <% end -%> + +
+ <% else -%> +
+ + + <% if attribute.field_type == :text_area -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> + <% else -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> + <% end -%> +
+ <% if with_sentinels? -%> + + <% end -%> + <% end -%> + + <% end -%> + +
+ +
+
<% attributes.each do |attribute| -%>
From 41116bcc029ff7337b6c1ba0c9749262c3ab535b Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 15:17:47 -0500 Subject: [PATCH 05/47] Add more form input types --- .../resource/templates/views/index.html.erb | 48 ++++++++++-- .../resource/templates/views/show.html.erb | 76 ++++++++++++++----- 2 files changed, 96 insertions(+), 28 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 89cb089d..8b27ffe9 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -25,13 +25,13 @@ <% if attribute.field_type == :check_box -%>
- <% if with_sentinels? -%> + <% if with_sentinels? -%> - <% end -%> + <% end -%> - <% if with_sentinels? -%> + <% if with_sentinels? -%> - <% end -%> + <% end -%> @@ -43,13 +43,45 @@ <% if attribute.field_type == :text_area -%> - <% if with_sentinels? -%> + <% if with_sentinels? -%> - <% end -%> + <% end -%> - <% if with_sentinels? -%> + <% if with_sentinels? -%> - <% end -%> + <% end -%> + <% elsif attribute.field_type == :datetime -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> + <% elsif attribute.field_type == :date -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> + <% elsif attribute.field_type == :time -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> + <% elsif attribute.field_type == :integer -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> <% else -%> <% if with_sentinels? -%> diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 485c2d50..7f51a5bc 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -57,13 +57,13 @@ <% if attribute.field_type == :check_box -%>
- <% if with_sentinels? -%> - - <% end -%> + <% if with_sentinels? -%> + + <% end -%> .<%= attribute.column_name %> %>> - <% if with_sentinels? -%> - - <% end -%> + <% if with_sentinels? -%> + + <% end -%> @@ -75,21 +75,57 @@ <% if attribute.field_type == :text_area -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> + <% elsif attribute.field_type == :datetime -%> + + <% if with_sentinels? -%> + + <% end -%> + <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <% if with_sentinels? -%> + + <% end -%> + <% elsif attribute.field_type == :date -%> + + <% if with_sentinels? -%> + + <% end -%> + <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <% if with_sentinels? -%> + + <% end -%> + <% elsif attribute.field_type == :time -%> + + <% if with_sentinels? -%> + + <% end -%> + <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <% if with_sentinels? -%> + + <% end -%> + <% elsif attribute.field_type == :integer -%> + + <% if with_sentinels? -%> + + <% end -%> + <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <% if with_sentinels? -%> + + <% end -%> <% else -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + <% if with_sentinels? -%> + + <% end -%> + + <% if with_sentinels? -%> + + <% end -%> <% end -%>
<% if with_sentinels? -%> From dca7f31beddad05d51759fca4e2b6014783ca8bb Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 15:19:53 -0500 Subject: [PATCH 06/47] wip --- .../draft/resource/templates/views/show.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 7f51a5bc..bbd6e3ec 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -87,7 +87,7 @@ <% if with_sentinels? -%> <% end -%> - <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <% if with_sentinels? -%> <% end -%> @@ -96,7 +96,7 @@ <% if with_sentinels? -%> <% end -%> - <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <% if with_sentinels? -%> <% end -%> @@ -105,7 +105,7 @@ <% if with_sentinels? -%> <% end -%> - <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <% if with_sentinels? -%> <% end -%> @@ -114,7 +114,7 @@ <% if with_sentinels? -%> <% end -%> - <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <% if with_sentinels? -%> <% end -%> From ee3488afb216fa90fdaff75036ffaf84b1c3cae9 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 15:24:33 -0500 Subject: [PATCH 07/47] wip --- .../resource/templates/views/show.html.erb | 56 +++++-------------- 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index bbd6e3ec..255392b9 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -75,57 +75,29 @@ <% if attribute.field_type == :text_area -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + + + <% elsif attribute.field_type == :datetime -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + + <% elsif attribute.field_type == :date -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + + <% elsif attribute.field_type == :time -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + + <% elsif attribute.field_type == :integer -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + + <% else -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + + + <% end -%>
<% if with_sentinels? -%> From e0b2c97a000c0ec044c5c3388e953263dd16a071 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 15:36:25 -0500 Subject: [PATCH 08/47] wip --- .../resource/templates/views/index.html.erb | 77 +++++-------------- 1 file changed, 19 insertions(+), 58 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 8b27ffe9..21a7ac42 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -10,28 +10,16 @@
- <% if with_sentinels? -%> - - <% end -%>
method="post"<% end -%>> - <% if with_sentinels? -%> - - <% end -%> - + <% attributes.each do |attribute| -%> - <% if with_sentinels? -%> - - <% end -%> + <% if attribute.field_type == :check_box -%>
- <% if with_sentinels? -%> - - <% end -%> + - <% if with_sentinels? -%> - - <% end -%> + @@ -42,59 +30,32 @@ <%= attribute.column_name.humanize %> + <% end -%> <% if attribute.field_type == :text_area -%> - <% if with_sentinels? -%> - - <% end -%> + - <% if with_sentinels? -%> - - <% end -%> + <% elsif attribute.field_type == :datetime -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + + + <% elsif attribute.field_type == :date -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + + + <% elsif attribute.field_type == :time -%> - <% if with_sentinels? -%> - - <% end -%> + - <% if with_sentinels? -%> - - <% end -%> + <% elsif attribute.field_type == :integer -%> - <% if with_sentinels? -%> - - <% end -%> - - <% if with_sentinels? -%> - - <% end -%> + + + <% else -%> - <% if with_sentinels? -%> - - <% end -%> - <% if with_sentinels? -%> - - <% end -%> <% end -%>
- <% if with_sentinels? -%> - - <% end -%> + <% end -%> <% end -%> From 4ca84ba22f06d88ba3cf7d5fcef64846c3438326 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 15:39:32 -0500 Subject: [PATCH 09/47] Remove extra field types --- .../resource/templates/views/index.html.erb | 16 ---------------- .../draft/resource/templates/views/show.html.erb | 16 ---------------- 2 files changed, 32 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 21a7ac42..3a7c8e18 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -35,22 +35,6 @@ - <% elsif attribute.field_type == :datetime -%> - - - - <% elsif attribute.field_type == :date -%> - - - - <% elsif attribute.field_type == :time -%> - - - - <% elsif attribute.field_type == :integer -%> - - - <% else -%> <% end -%> diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 255392b9..0cebe85c 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -78,22 +78,6 @@ - <% elsif attribute.field_type == :datetime -%> - - - - <% elsif attribute.field_type == :date -%> - - - - <% elsif attribute.field_type == :time -%> - - - - <% elsif attribute.field_type == :integer -%> - - - <% else -%> From 4edd0fc9140c713413a384c96215359099371ad8 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 15:52:10 -0500 Subject: [PATCH 10/47] Revert "Remove extra field types" This reverts commit 4ca84ba22f06d88ba3cf7d5fcef64846c3438326. --- .../resource/templates/views/index.html.erb | 16 ++++++++++++++++ .../draft/resource/templates/views/show.html.erb | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 3a7c8e18..21a7ac42 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -35,6 +35,22 @@ + <% elsif attribute.field_type == :datetime -%> + + + + <% elsif attribute.field_type == :date -%> + + + + <% elsif attribute.field_type == :time -%> + + + + <% elsif attribute.field_type == :integer -%> + + + <% else -%> <% end -%> diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 0cebe85c..255392b9 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -78,6 +78,22 @@ + <% elsif attribute.field_type == :datetime -%> + + + + <% elsif attribute.field_type == :date -%> + + + + <% elsif attribute.field_type == :time -%> + + + + <% elsif attribute.field_type == :integer -%> + + + <% else -%> From 7ced4c5d0cc48a8e4684bfa1408e8f6e040fc7ae Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 15:55:45 -0500 Subject: [PATCH 11/47] Remove end at line 61 --- .../resource/templates/views/index.html.erb | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 21a7ac42..f56aa6e6 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -14,51 +14,50 @@ <% attributes.each do |attribute| -%> - <% if attribute.field_type == :check_box -%> -
- - - - - -
- <% else -%> -
- + <% if attribute.field_type == :check_box -%> +
+ - <% end -%> - <% if attribute.field_type == :text_area -%> + - + +
+ <% else -%> +
+ - <% elsif attribute.field_type == :datetime -%> + <% end -%> + <% if attribute.field_type == :text_area -%> - + - <% elsif attribute.field_type == :date -%> + <% elsif attribute.field_type == :datetime -%> - + - <% elsif attribute.field_type == :time -%> + <% elsif attribute.field_type == :date -%> - + - <% elsif attribute.field_type == :integer -%> + <% elsif attribute.field_type == :time -%> - + - <% else -%> - - <% end -%> -
+ <% elsif attribute.field_type == :integer -%> - <% end -%> + + + <% else -%> + + <% end -%> +
<% end -%> + From e73c37be11f204cca4cece724d0cc104049bd231 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 16:02:46 -0500 Subject: [PATCH 12/47] try forcing fieldtype default --- lib/generators/draft/resource/templates/views/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index f56aa6e6..9ed35026 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -52,7 +52,7 @@ <% else -%> - + <% end -%> From 6b24a9186691b8a2df604de1ff9d8c927ddfcfc4 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 16:04:45 -0500 Subject: [PATCH 13/47] wip --- lib/generators/draft/resource/templates/views/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 9ed35026..ad55fad7 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -52,7 +52,7 @@ <% else -%> - + <% end -%> From f2abf75ff03270fc48bcb79f027f6aa0bd334f06 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 16:07:47 -0500 Subject: [PATCH 14/47] wip --- lib/generators/draft/resource/templates/views/index.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index ad55fad7..954fee0c 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -35,7 +35,7 @@ - <% elsif attribute.field_type == :datetime -%> + <% elsif attribute.field_type.to_s.gsub("_select") == :datetime -%> @@ -52,7 +52,7 @@ <% else -%> - + <% end -%> From deebe22eb4257082f1e0abb3398cab3afb55e76a Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 16:10:58 -0500 Subject: [PATCH 15/47] MM --- lib/generators/draft/resource/templates/views/index.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 954fee0c..32d73eed 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -52,6 +52,8 @@ <% else -%> + <%= attribute.field_type.to_s %> + <%= attribute.field_type.to_s.gsub("_select") %> <% end -%> From eb67328d80ebf7da17140f149c98aeca5824451b Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 16:14:34 -0500 Subject: [PATCH 16/47] Summer will last forever --- .../draft/resource/templates/views/index.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 32d73eed..0ae0684a 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -35,25 +35,25 @@ - <% elsif attribute.field_type.to_s.gsub("_select") == :datetime -%> + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> - <% elsif attribute.field_type == :date -%> + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> - <% elsif attribute.field_type == :time -%> + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%> - <% elsif attribute.field_type == :integer -%> + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%> <% else -%> <%= attribute.field_type.to_s %> - <%= attribute.field_type.to_s.gsub("_select") %> + <%= attribute.field_type.to_s.gsub(/_.*/, "").to_sym %> <% end -%> From 5898bb787ebffbf40bf3a2f4c639aa09d9c0da80 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 16:19:38 -0500 Subject: [PATCH 17/47] Upper --- lib/generators/draft/resource/templates/views/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 0ae0684a..e9d9bfdc 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -37,7 +37,7 @@ <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> From ba326b3d31fbd480baca270a1208d9ee43105409 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 16:28:40 -0500 Subject: [PATCH 18/47] fix some spacing --- lib/generators/draft/resource/templates/views/index.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index e9d9bfdc..7d53d718 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -25,7 +25,7 @@ <% else -%> -
+
@@ -56,7 +56,7 @@ <%= attribute.field_type.to_s.gsub(/_.*/, "").to_sym %> <% end -%> -
+
<% end -%> From cfc92b2e6639a7eddf4aa329c68ab9b53f65a8ca Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 16:33:04 -0500 Subject: [PATCH 19/47] redirect_to not back --- .../draft/resource/templates/controllers/controller.rb | 6 +++--- .../draft/resource/templates/views/index.html.erb | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 4614548f..4bb04d2c 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -44,10 +44,10 @@ def create end format.html do - redirect_back({ :fallback_location => "/<%= plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> created successfully."}) + redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> created successfully."}) end end - redirect_back({ :fallback_location => "/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> created successfully."}) + else respond_to do |format| format.json do @@ -55,7 +55,7 @@ def create end format.html do - redirect_back({ :fallback_location => "/<%= plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> failed to create successfully."}) + redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> failed to create successfully."}) end end end diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 7d53d718..ab994c90 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -52,8 +52,6 @@ <% else -%> - <%= attribute.field_type.to_s %> - <%= attribute.field_type.to_s.gsub(/_.*/, "").to_sym %> <% end -%> From 8d7703f9ef008ebe19ae93f7d2e539799b4cf20b Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 17:06:58 -0500 Subject: [PATCH 20/47] wip --- lib/generators/draft/resource/resource_generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 7a6434d6..746d0fc1 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -69,7 +69,7 @@ def golden_five_routes # Routes for the #{singular_table_name.humanize} resource: # CREATE - match("/post_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create", :via => "#{skip_post? ? "get" : "post"}"}) + match("/insert_#{singular_table_name}", { :controller => "#{plural_table_name}", :action => "create", :via => "#{skip_post? ? "get" : "post"}"}) # READ match("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index", :via => "get"}) @@ -78,7 +78,7 @@ def golden_five_routes # UPDATE - match("/patch_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "update", :via => "#{skip_post? ? "get" : "post"}"}) + match("/modify_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "update", :via => "#{skip_post? ? "get" : "post"}"}) # DELETE match("/delete_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "destroy", :via => "get"}) From c4d66c842445f9cad20e69c8834fc3c5ae3ec470 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 8 Aug 2019 17:07:41 -0500 Subject: [PATCH 21/47] wip --- lib/generators/draft/resource/templates/views/index.html.erb | 2 +- lib/generators/draft/resource/templates/views/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index ab994c90..752555ec 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -10,7 +10,7 @@
- method="post"<% end -%>> + method="post"<% end -%>> <% attributes.each do |attribute| -%> diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 255392b9..0546fd8d 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -45,7 +45,7 @@ <% if with_sentinels? -%> <% end -%> - method="post"<% end -%>> + method="post"<% end -%>> <% if with_sentinels? -%> <% end -%> From 020f63e98884d7c1ebbe30d26ca2239e0fcce2bb Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 13 Aug 2019 15:18:06 -0500 Subject: [PATCH 22/47] Replace rt_ with route_ --- lib/generators/draft/resource/resource_generator.rb | 8 ++++---- .../draft/resource/templates/controllers/controller.rb | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 746d0fc1..43547a8a 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -74,14 +74,14 @@ def golden_five_routes # READ match("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index", :via => "get"}) - match("/#{plural_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "show", :via => "get"}) + match("/#{plural_table_name}/:route_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "show", :via => "get"}) # UPDATE - match("/modify_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "update", :via => "#{skip_post? ? "get" : "post"}"}) + match("/modify_#{singular_table_name}/:route_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "update", :via => "#{skip_post? ? "get" : "post"}"}) # DELETE - match("/delete_#{singular_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "destroy", :via => "get"}) + match("/delete_#{singular_table_name}/:route_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "destroy", :via => "get"}) #------------------------------ RUBY @@ -96,7 +96,7 @@ def read_only_routes # READ match("/#{plural_table_name}", { :controller => "#{plural_table_name}", :action => "index", :via => "get"}) - match("/#{plural_table_name}/:rt_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "show", :via => "get"}) + match("/#{plural_table_name}/:route_#{singular_table_name}_id", { :controller => "#{plural_table_name}", :action => "show", :via => "get"}) #------------------------------ RUBY diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 4bb04d2c..353c6c30 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -14,7 +14,7 @@ def index end def show - the_id = params.fetch(:rt_<%= singular_table_name %>_id) + the_id = params.fetch(:route_<%= singular_table_name %>_id) @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({:id => the_id }).first respond_to do |format| @@ -73,7 +73,7 @@ def create end def update - the_id = params.fetch(:rt_<%= singular_table_name %>_id) + the_id = params.fetch(:route_<%= singular_table_name %>_id) @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where(:id => the_id).at(0) <% attributes.each do |attribute| -%> @@ -122,7 +122,7 @@ def update end def destroy - the_id = params.fetch(:rt_<%= singular_table_name %>_id) + the_id = params.fetch(:route_<%= singular_table_name %>_id) @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).first @<%= singular_table_name.underscore %>.destroy From 9f77c0462317e1da2e32aea538ceef41a5dfccb3 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 13 Aug 2019 15:22:27 -0500 Subject: [PATCH 23/47] Fix controller indentation --- .../resource/templates/controllers/controller.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 353c6c30..bf26243b 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -128,15 +128,15 @@ def destroy @<%= singular_table_name.underscore %>.destroy <% unless skip_validation_alerts? -%> - respond_to do |format| - format.json do - render({ :json => @<%= singular_table_name.underscore %>.as_json }) - end + respond_to do |format| + format.json do + render({ :json => @<%= singular_table_name.underscore %>.as_json }) + end - format.html do - redirect_to("/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> deleted successfully."}) + format.html do + redirect_to("/<%= @plural_table_name.underscore %>", {:notice => "<%= singular_table_name.humanize %> deleted successfully."}) + end end - end <% else -%> <% unless skip_redirect? -%> redirect_to("/<%= @plural_table_name.underscore %>") From ad68007ccc016036fa7e66712612d72548bc8e23 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 13 Aug 2019 15:32:44 -0500 Subject: [PATCH 24/47] Fix index form indentation --- .../resource/templates/views/index.html.erb | 88 ++++++++----------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 752555ec..c81fd027 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -3,70 +3,58 @@

List of all <%= plural_table_name.humanize.downcase %>

+ + +
+ +
+

Add a new <%= singular_table_name.humanize.downcase %>

-
- method="post"<% end -%>> - - <% attributes.each do |attribute| -%> - - <% if attribute.field_type == :check_box -%> -
- - - - - -
- <% else -%> -
- - - <% end -%> - <% if attribute.field_type == :text_area -%> - - - - <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> - +<% attributes.each do |attribute| -%> +<% if attribute.field_type == :check_box -%> +
+ + + +
+ +<% else -%> +
+ + +<% if attribute.field_type == :text_area -%> + +<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> - - <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> - +<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> +<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%> + +<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%> + +<% else -%> + +<% end -%> +
- <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%> - - - - <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%> - - - - <% else -%> - - <% end -%> -
- - <% end -%> - +<% end -%> +<% end -%> - -
+
+ <% if with_sentinels? -%> @@ -75,10 +63,10 @@ -<% end -%>
+<% end -%>
@@ -157,3 +145,5 @@
+ +
From eac9e1b85c4987b5665479f8ccbc8eb7c3e63714 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 13 Aug 2019 15:59:24 -0500 Subject: [PATCH 25/47] Fix show page form --- .../templates/controllers/controller.rb | 4 + .../resource/templates/views/index.html.erb | 1 - .../resource/templates/views/show.html.erb | 139 +++++++----------- 3 files changed, 56 insertions(+), 88 deletions(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index bf26243b..fded317f 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -77,7 +77,11 @@ def update @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where(:id => the_id).at(0) <% attributes.each do |attribute| -%> +<% if attribute.field_type == :check_box -%> + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch(:<%= attribute.column_name %>, false) +<% else %> @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch(:<%= attribute.column_name %>, @<%= singular_table_name.underscore %>.<%= attribute.column_name %>) +<% end %> <% end -%> <% unless skip_validation_alerts? -%> diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index c81fd027..d0f3b046 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -54,7 +54,6 @@
- <% if with_sentinels? -%> diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 0546fd8d..a33d1674 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -11,16 +11,6 @@ -<% if with_sentinels? -%> - -<% end -%> -
- -
-<% if with_sentinels? -%> - -<% end -%> - <% unless read_only? -%> <% if with_sentinels? -%> @@ -35,84 +25,7 @@ <% end -%> <% end -%> -
-

- Edit <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %> -

- -
- - <% if with_sentinels? -%> - - <% end -%> -
method="post"<% end -%>> - <% if with_sentinels? -%> - - <% end -%> - - <% attributes.each do |attribute| -%> - <% if with_sentinels? -%> - - <% end -%> - <% if attribute.field_type == :check_box -%> -
- - <% if with_sentinels? -%> - - <% end -%> - .<%= attribute.column_name %> %>> - <% if with_sentinels? -%> - - <% end -%> - -
- <% else -%> -
- - - <% if attribute.field_type == :text_area -%> - - - - <% elsif attribute.field_type == :datetime -%> - - - - <% elsif attribute.field_type == :date -%> - - - - <% elsif attribute.field_type == :time -%> - - - - <% elsif attribute.field_type == :integer -%> - - - - <% else -%> - - - <% end -%> -
- <% if with_sentinels? -%> - - <% end -%> - <% end -%> - - <% end -%> - -
- -
-
<% attributes.each do |attribute| -%>
@@ -158,8 +71,60 @@ +
+ <% if with_sentinels? -%> <% end -%> + +
+
+

+ Edit <%= singular_table_name.humanize.downcase %> +

+ +
method="post" <% end -%>> +<% attributes.each do |attribute| -%> +<% if attribute.field_type == :check_box -%> +
+ .<%= attribute.column_name %> %>> + + +
+ +<% else -%> +
+ + +<% if attribute.field_type == :text_area -%> + +<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> + +<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> + +<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%> + +<% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%> + +<% else -%> + +<% end -%> +
+ +<% end -%> +<% end -%> + +
+
+
+ +
From 7a618af063b5037151b0ff0a7ac2d00c8ac24e39 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 13 Aug 2019 16:16:22 -0500 Subject: [PATCH 26/47] Make the new form narrower --- lib/generators/draft/resource/templates/views/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index d0f3b046..b962d55a 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -9,7 +9,7 @@
-
+

Add a new <%= singular_table_name.humanize.downcase %>

From eb185c8ead13554aa299602398f2bcf96c6a1a83 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 13 Aug 2019 16:17:38 -0500 Subject: [PATCH 27/47] Order index by created at descending --- .../draft/resource/templates/controllers/controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index fded317f..5e5cd7cb 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -1,6 +1,6 @@ class <%= plural_table_name.camelize %>Controller < ApplicationController def index - @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all + @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all.order({ :created_at => :desc }) respond_to do |format| format.json do From b18e9dde563fc195298a046452ad4fe745d3f837 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 13 Aug 2019 16:28:29 -0500 Subject: [PATCH 28/47] Add margin-bottom to custom-checkboxes --- lib/generators/draft/resource/templates/views/index.html.erb | 2 +- lib/generators/draft/resource/templates/views/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index b962d55a..105b0ae0 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -17,7 +17,7 @@
method="post"<% end -%>> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> -
+
diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index a33d1674..0fb00901 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -88,7 +88,7 @@ method="post" <% end -%>> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> -
+
.<%= attribute.column_name %> %>>
From e32cae19afbe0f9a1a3cdf1854699b88b5f64554 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Wed, 20 Nov 2019 17:26:07 -0600 Subject: [PATCH 30/47] Update draft:layout rename _bootstrapcdn_assets to _cdn_assets blacklist default rails routes update layout.html.erb with rails 6 helpers Update cdn resources Only allow GET routes in navbar --- .../draft/layout/layout_generator.rb | 6 ++--- .../templates/_bootstrapcdn_assets.html.erb | 10 -------- .../layout/templates/_cdn_assets.html.erb | 13 +++++++++++ .../draft/layout/templates/layout.html.erb | 23 ++++++++++--------- 4 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb create mode 100644 lib/generators/draft/layout/templates/_cdn_assets.html.erb diff --git a/lib/generators/draft/layout/layout_generator.rb b/lib/generators/draft/layout/layout_generator.rb index e4b3c7e2..5340ef0a 100644 --- a/lib/generators/draft/layout/layout_generator.rb +++ b/lib/generators/draft/layout/layout_generator.rb @@ -29,7 +29,7 @@ def generate_layout template "_flashes.html.erb", "app/views/shared/_flashes.html.erb" unless skip_cdn? - template "_bootstrapcdn_assets.html.erb", "app/views/shared/_bootstrapcdn_assets.html.erb" + template "_cdn_assets.html.erb", "app/views/shared/_cdn_assets.html.erb" end end @@ -50,7 +50,7 @@ def skip_cdn? end def app_resources - route_names.reject { |name| /^rails_info.*/.match(name) || /^rails_mailers.*/.match(name) || name.pluralize != name } + route_names.reject { |name| /^rails_*/.match(name) || /batch_action*/.match(name) || /admin_*/.match(name) || name.pluralize != name } end def devise_routes @@ -60,7 +60,7 @@ def devise_routes end def route_names - @route_names ||= Rails.application.routes.routes.map(&:name).uniq.compact + @route_names ||= Rails.application.routes.routes.reject { |route| route.verb != "GET" }.map(&:name).uniq.compact end end end diff --git a/lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb b/lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb deleted file mode 100644 index 1c658843..00000000 --- a/lib/generators/draft/layout/templates/_bootstrapcdn_assets.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<% if bootswatch? -%> - -<% else -%> - -<% end -%> - - - - - diff --git a/lib/generators/draft/layout/templates/_cdn_assets.html.erb b/lib/generators/draft/layout/templates/_cdn_assets.html.erb new file mode 100644 index 00000000..c87ed4ee --- /dev/null +++ b/lib/generators/draft/layout/templates/_cdn_assets.html.erb @@ -0,0 +1,13 @@ + +<% if bootswatch? -%> + +<% else -%> + +<% end -%> + + + + + + + diff --git a/lib/generators/draft/layout/templates/layout.html.erb b/lib/generators/draft/layout/templates/layout.html.erb index 37e68178..0bd850ee 100644 --- a/lib/generators/draft/layout/templates/layout.html.erb +++ b/lib/generators/draft/layout/templates/layout.html.erb @@ -5,23 +5,24 @@ <%= Rails.application.class.parent_name %> -<% unless skip_cdn? -%> - <%%= render "shared/bootstrapcdn_assets" %> + + + + + -<% end -%> <%%= csrf_meta_tags %> - - <%%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> - - - - + <%%= csp_meta_tag %> + + <%%= stylesheet_link_tag 'application', media: 'all' %> + <%%= javascript_pack_tag 'application' %> + + + <%%= render "shared/cdn_assets" %> - From c00f9f28d85607512a06f25867b6e89a6b80b92f Mon Sep 17 00:00:00 2001 From: jelaniwoods Date: Tue, 27 Aug 2019 22:47:33 -0500 Subject: [PATCH 31/47] Add account generator --- .../draft/account/account_generator.rb | 196 ++++++++++++++++++ .../templates/controllers/controller.rb | 65 ++++++ .../controllers/sessions_controller.rb | 34 +++ .../templates/views/edit_profile.html.erb | 38 ++++ .../views/edit_profile_with_errors.html.erb | 44 ++++ .../templates/views/sessions/sign_in.html.erb | 23 ++ .../templates/views/sessions/sign_up.html.erb | 43 ++++ 7 files changed, 443 insertions(+) create mode 100644 lib/generators/draft/account/account_generator.rb create mode 100644 lib/generators/draft/account/templates/controllers/controller.rb create mode 100644 lib/generators/draft/account/templates/controllers/sessions_controller.rb create mode 100644 lib/generators/draft/account/templates/views/edit_profile.html.erb create mode 100644 lib/generators/draft/account/templates/views/edit_profile_with_errors.html.erb create mode 100644 lib/generators/draft/account/templates/views/sessions/sign_in.html.erb create mode 100644 lib/generators/draft/account/templates/views/sessions/sign_up.html.erb diff --git a/lib/generators/draft/account/account_generator.rb b/lib/generators/draft/account/account_generator.rb new file mode 100644 index 00000000..9df9d1ab --- /dev/null +++ b/lib/generators/draft/account/account_generator.rb @@ -0,0 +1,196 @@ +require "rails/generators/named_base" + +module Draft + class AccountGenerator < Rails::Generators::NamedBase + source_root File.expand_path("../templates", __FILE__) + + argument :attributes, type: :array, default: [], + banner: "field:type field:type" + + include Rails::Generators::ResourceHelpers + + def generate_required_attributes + unless attributes_has_password_digest? + password_digest = Rails::Generators::GeneratedAttribute.parse(["password_digest", :string, nil].compact.join(":")) + attributes.unshift(password_digest) + end + unless attributes_has_email? + email = Rails::Generators::GeneratedAttribute.parse(["email", :string, nil].compact.join(":")) + attributes.unshift(email) + end + end + + def generate_model + invoke "draft:model", paramaterize_attributes + edit_model + end + + def generate_routes + authentication_routes + end + + def generate_before_actions + authentication_helpers + end + + def generate_controller + template "controllers/sessions_controller.rb", "app/controllers/#{singular_table_name.underscore}_sessions_controller.rb" + template "controllers/controller.rb", "app/controllers/#{plural_table_name.underscore}_controller.rb" + end + + def create_root_folder + empty_directory File.join("app/views", "#{singular_table_name.underscore}_sessions") + empty_directory File.join("app/views", "#{plural_table_name.underscore}") + end + + def generate_view_files + available_views.select{|filename| filename.include?("sign")}.each do |view| + filename = view_sessions_filename_with_extensions(view) + template filename, File.join("app/views/#{singular_table_name.underscore}_sessions", File.basename(filename)) + end + + available_views.reject{|filename| filename.include?("sign")}.each do |view| + filename = view_filename_with_extensions(view) + template filename, File.join("app/views/#{plural_table_name.underscore}", File.basename(filename)) + end + end + + private + + def authentication_routes + log :route, "Authentication routes" + + route <<-RUBY.gsub(/^ /, "") + + # Routes for signing up + + match("/#{singular_table_name.underscore}_sign_up", { :controller => "#{plural_table_name.underscore}", :action => "new_registration_form", :via => "get"}) + + # Routes for signing in + match("/#{singular_table_name.underscore}_sign_in", { :controller => "#{singular_table_name.underscore}_sessions", :action => "new_session_form", :via => "get"}) + + match("/#{singular_table_name.underscore}_verify_credentials", { :controller => "#{singular_table_name.underscore}_sessions", :action => "add_cookie", :via => "post"}) + + # Route for signing out + + match("/#{singular_table_name.underscore}_sign_out", { :controller => "#{singular_table_name.underscore}_sessions", :action => "remove_cookies", :via => "get"}) + + # Route for creating account into database + + match("/post_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "create", :via => "post" }) + + # Route for editing account + + match("/edit_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "edit_registration_form", :via => "get"}) + + match("/patch_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "update", :via => "post"}) + + # Route for removing an account + + match("/cancel_#{singular_table_name.underscore}_account", { :controller => "#{plural_table_name.underscore}", :action => "destroy", :via => "get"}) + + + #------------------------------ + RUBY + end + + def authentication_helpers + log :controller, "Authentication before_actions" + + application_controller <<-RUBY.gsub(/^ /, "") + + before_action(:load_current_#{singular_table_name.underscore}) + before_action(:force_#{singular_table_name.underscore}_sign_in) + + def load_current_#{singular_table_name.underscore} + the_id = session.fetch(:#{singular_table_name.underscore}_id) + @current_#{singular_table_name.underscore} = #{class_name.singularize}.where({ :id => the_id }).at(0) + end + + def force_#{singular_table_name.underscore}_sign_in + if @current_#{singular_table_name.underscore} == nil + redirect_to("/#{singular_table_name.underscore}_sign_in", { :notice => "You have to sign in first." }) + end + end + RUBY + end + + def edit_model + sentinel = /.*ApplicationRecord\n/ + content = " validates :email, :uniqueness => { :case_sensitive => false }\n"\ + " validates :email, :presence => true\n"\ + " has_secure_password\n" + if model_exists? + inside "app/models" do + insert_into_file "#{singular_table_name.underscore}.rb", content, after: sentinel + end + end + end + + def route(routing_code) + sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/ + + inside "config" do + insert_into_file "routes.rb", routing_code, after: sentinel + end + end + + def application_controller(app_code) + sentinel = /::Base$/ + + inside "app/controllers" do + insert_into_file "application_controller.rb", app_code, after: sentinel + end + end + + def available_views + %w(sign_up sign_in edit_profile edit_profile_with_errors) + end + + def view_filename_with_extensions(name) + filename = [name, :html, :erb].compact.join(".") + folders = ["views"] + filename = File.join(folders, filename) if folders.any? + filename + end + + def view_sessions_filename_with_extensions(name) + filename = [name, :html, :erb].compact.join(".") + folders = ["views", "sessions"] + filename = File.join(folders, filename) if folders.any? + filename + end + + def controller_filename_with_extensions(name) + filename = [name,:rb].compact.join(".") + folders = ["controllers"] + filename = File.join(folders, filename) if folders.any? + filename + end + + def model_exists? + File.exist?(File.join(destination_root, model_path)) + end + + def model_path + @model_path ||= File.join("app", "models", "#{file_path}.rb") + end + + def attributes_has_email? + attributes.any? { |attribute| attribute.column_name.include?("email") } + end + + def attributes_has_password_digest? + attributes.any?{ |attribute| attribute.column_name.include?("password_digest") } + end + + def paramaterize_attributes + array = [singular_table_name.underscore] + attributes.each do |attribute| + array.push(attribute.column_name + ":" + attribute.type.to_s) + end + array + end + + end +end diff --git a/lib/generators/draft/account/templates/controllers/controller.rb b/lib/generators/draft/account/templates/controllers/controller.rb new file mode 100644 index 00000000..e39a6249 --- /dev/null +++ b/lib/generators/draft/account/templates/controllers/controller.rb @@ -0,0 +1,65 @@ +class <%= class_name.pluralize %>Controller < ApplicationController + skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:new_registration_form, :create] }) + + def new_registration_form + render({ :template => "<%=singular_table_name.underscore %>_sessions/sign_up.html.erb" }) + end + + def create + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new +<% attributes.each do |attribute| -%> +<% if attribute.field_type == :check_box -%> + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_query", false) +<% elsif attribute.column_name != "password_digest" -%> + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_query") +<% else -%> + @<%= singular_table_name.underscore %>.password = params.fetch("password_from_query") + @<%= singular_table_name.underscore %>.password_confirmation = params.fetch("password_confirmation_from_query") +<% end -%> +<% end -%> + + save_status = @<%= singular_table_name.underscore %>.save + + if save_status == true + session.store(:<%= singular_table_name.underscore %>_id, @<%= singular_table_name.underscore %>.id) + + redirect_to("/", { :notice => "<%= singular_table_name.humanize %> account created successfully."}) + else + redirect_to("/<%=singular_table_name.underscore %>_sign_up", { :alert => "<%= singular_table_name.humanize %> account failed to create successfully."}) + end + end + + def edit_registration_form + render({ :template => "<%= plural_table_name.underscore %>/edit_profile.html.erb" }) + end + + def update + @<%= singular_table_name.underscore %> = @current_<%= singular_table_name.underscore %> +<% attributes.each do |attribute| -%> +<% if attribute.field_type == :check_box -%> + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_query", false) +<% elsif attribute.column_name != "password_digest" -%> + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_query") +<% else -%> + @<%= singular_table_name.underscore %>.password = params.fetch("password_from_query") + @<%= singular_table_name.underscore %>.password_confirmation = params.fetch("password_confirmation_from_query") +<% end -%> +<% end -%> + + if @<%= singular_table_name.underscore %>.valid? + @<%= singular_table_name.underscore %>.save + + redirect_to("/", { :notice => "<%= singular_table_name.humanize %> account updated successfully."}) + else + render({ :template => "<%= plural_table_name.underscore %>/edit_profile_with_errors.html.erb" }) + end + end + + def destroy + @current_<%= singular_table_name.underscore %>.destroy + reset_session + + redirect_to("/", { :notice => "<%= class_name.singularize %> account cancelled" }) + end + +end diff --git a/lib/generators/draft/account/templates/controllers/sessions_controller.rb b/lib/generators/draft/account/templates/controllers/sessions_controller.rb new file mode 100644 index 00000000..f2961b5f --- /dev/null +++ b/lib/generators/draft/account/templates/controllers/sessions_controller.rb @@ -0,0 +1,34 @@ +class <%= class_name.singularize %>SessionsController < ApplicationController + skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:new_session_form, :add_cookie] }) + + def new_session_form + render({ :template => "<%=singular_table_name.underscore %>_sessions/sign_in.html.erb" }) + end + + def add_cookie + <%=singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :email => params.fetch("email") }).at(0) + + the_supplied_password = params.fetch(:password) + + if <%=singular_table_name.underscore %> != nil + are_they_legit = <%=singular_table_name.underscore %>.authenticate(the_supplied_password) + + if are_they_legit == false + redirect_to("/sign_in", { :alert => "Password incorrect." }) + else + session.store(:<%=singular_table_name.underscore %>_id, <%=singular_table_name.underscore %>.id) + + redirect_to("/", { :notice => "Signed in successfully." }) + end + else + redirect_to("/<%=singular_table_name.underscore %>_sign_in", { :alert => "There's no <%=singular_table_name.underscore %> account with that email address." }) + end + end + + def remove_cookies + reset_session + + redirect_to("/", { :notice => "Signed out successfully." }) + end + +end diff --git a/lib/generators/draft/account/templates/views/edit_profile.html.erb b/lib/generators/draft/account/templates/views/edit_profile.html.erb new file mode 100644 index 00000000..32bc62e3 --- /dev/null +++ b/lib/generators/draft/account/templates/views/edit_profile.html.erb @@ -0,0 +1,38 @@ +
+
+ Edit <%= class_name.titleize %> Account +
+ +
+
+<% attributes.each do |attribute| -%> +<% if attribute.column_name != "password_digest" -%> +
+ +<% if attribute.field_type == :text_area -%> + +<% elsif attribute.field_type == :check_box -%> + +<% else -%> + +<% end -%> +
+<% end -%> +<% end -%> + +
+ + +
+ +
+ + +
+ + +
+
+
diff --git a/lib/generators/draft/account/templates/views/edit_profile_with_errors.html.erb b/lib/generators/draft/account/templates/views/edit_profile_with_errors.html.erb new file mode 100644 index 00000000..f6ac1b49 --- /dev/null +++ b/lib/generators/draft/account/templates/views/edit_profile_with_errors.html.erb @@ -0,0 +1,44 @@ +
+
+ Edit <%= class_name.titleize %> Account +
+ + <%% if @<%= singular_table_name %>.errors.any? %> + <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %> +
+ <%%= message %> +
+ <%% end %> + <%% end %> +
+
+ <% attributes.each do |attribute| -%> + <% if attribute.column_name != "password_digest" %> +
+ + <% if attribute.field_type == :text_area %> + + <% elsif attribute.field_type == :check_box %> + + <% else %> + + <% end %> +
+ <% end -%> + <% end %> +
+ + +
+ +
+ + +
+ + +
+
+
diff --git a/lib/generators/draft/account/templates/views/sessions/sign_in.html.erb b/lib/generators/draft/account/templates/views/sessions/sign_in.html.erb new file mode 100644 index 00000000..459b1901 --- /dev/null +++ b/lib/generators/draft/account/templates/views/sessions/sign_in.html.erb @@ -0,0 +1,23 @@ +

Sign in

+ +
+
+ + +
+ +
+ + +
+ + +
+ +
+ +

+ Or, Sign up instead. +

diff --git a/lib/generators/draft/account/templates/views/sessions/sign_up.html.erb b/lib/generators/draft/account/templates/views/sessions/sign_up.html.erb new file mode 100644 index 00000000..e905693e --- /dev/null +++ b/lib/generators/draft/account/templates/views/sessions/sign_up.html.erb @@ -0,0 +1,43 @@ +

Sign up

+ +
+ +
+ + +
+ <% attributes.each do |attribute| -%> + <% if attribute.column_name != "password_digest" && attribute.column_name != "email" -%> +
+ + <%- if attribute.field_type == :check_box -%> + + <%- elsif attribute.field_type == :text_area -%> + + <%- else -%> + + <%- end -%> +
+ <%- end -%> + <% end -%> + +
+ + +
+ +
+ + +
+ + +
+ +
+ +

+ Or, Sign in instead. +

From 0dd7bdff69534b3325579a7142c457bbf2f70c58 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Thu, 21 Nov 2019 13:46:22 -0600 Subject: [PATCH 32/47] Fix add_cookie param fetch --- .../account/templates/controllers/sessions_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/account/templates/controllers/sessions_controller.rb b/lib/generators/draft/account/templates/controllers/sessions_controller.rb index f2961b5f..60ddd1be 100644 --- a/lib/generators/draft/account/templates/controllers/sessions_controller.rb +++ b/lib/generators/draft/account/templates/controllers/sessions_controller.rb @@ -6,9 +6,9 @@ def new_session_form end def add_cookie - <%=singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :email => params.fetch("email") }).at(0) + <%=singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :email => params.fetch("email_from_query") }).at(0) - the_supplied_password = params.fetch(:password) + the_supplied_password = params.fetch("password_from_query") if <%=singular_table_name.underscore %> != nil are_they_legit = <%=singular_table_name.underscore %>.authenticate(the_supplied_password) From 4f5ab605dc1278071f566566a969f10ccb0de76f Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Tue, 26 Nov 2019 17:15:30 -0600 Subject: [PATCH 33/47] Fix sessions_controller redirect url --- .../draft/account/templates/controllers/sessions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/account/templates/controllers/sessions_controller.rb b/lib/generators/draft/account/templates/controllers/sessions_controller.rb index 60ddd1be..1325ac49 100644 --- a/lib/generators/draft/account/templates/controllers/sessions_controller.rb +++ b/lib/generators/draft/account/templates/controllers/sessions_controller.rb @@ -14,7 +14,7 @@ def add_cookie are_they_legit = <%=singular_table_name.underscore %>.authenticate(the_supplied_password) if are_they_legit == false - redirect_to("/sign_in", { :alert => "Password incorrect." }) + redirect_to("/<%=singular_table_name.underscore %>_sign_in", { :alert => "Password incorrect." }) else session.store(:<%=singular_table_name.underscore %>_id, <%=singular_table_name.underscore %>.id) From d7ccfa08d1c9eb00b9f7b935a0f8e0c812dfe9bd Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 18 Feb 2020 00:48:34 -0600 Subject: [PATCH 34/47] Winter 2020 updates --- .../draft/account/account_generator.rb | 50 +++++++++---------- .../templates/controllers/controller.rb | 18 +++---- .../controllers/sessions_controller.rb | 22 ++++---- .../templates/views/edit_profile.html.erb | 12 ++--- .../views/edit_profile_with_errors.html.erb | 12 ++--- .../templates/views/sessions/sign_in.html.erb | 4 +- .../templates/views/sessions/sign_up.html.erb | 14 +++--- .../draft/resource/resource_generator.rb | 14 +++--- .../templates/controllers/controller.rb | 14 +++--- .../resource/templates/views/index.html.erb | 14 +++--- .../resource/templates/views/show.html.erb | 14 +++--- 11 files changed, 93 insertions(+), 95 deletions(-) diff --git a/lib/generators/draft/account/account_generator.rb b/lib/generators/draft/account/account_generator.rb index 9df9d1ab..c566c024 100644 --- a/lib/generators/draft/account/account_generator.rb +++ b/lib/generators/draft/account/account_generator.rb @@ -62,34 +62,31 @@ def authentication_routes route <<-RUBY.gsub(/^ /, "") - # Routes for signing up - - match("/#{singular_table_name.underscore}_sign_up", { :controller => "#{plural_table_name.underscore}", :action => "new_registration_form", :via => "get"}) - - # Routes for signing in - match("/#{singular_table_name.underscore}_sign_in", { :controller => "#{singular_table_name.underscore}_sessions", :action => "new_session_form", :via => "get"}) - - match("/#{singular_table_name.underscore}_verify_credentials", { :controller => "#{singular_table_name.underscore}_sessions", :action => "add_cookie", :via => "post"}) - - # Route for signing out + # Routes for the #{singular_table_name.humanize} account: + + # SIGN UP FORM + get("/#{singular_table_name.underscore}_sign_up", { :controller => "#{plural_table_name.underscore}", :action => "new_registration_form" }) + # CREATE RECORD + post("/insert_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "create" }) + + # EDIT PROFILE FORM + get("/edit_#{singular_table_name.underscore}_profile", { :controller => "#{plural_table_name.underscore}", :action => "edit_registration_form" }) + # UPDATE RECORD + post("/modify_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "update" }) - match("/#{singular_table_name.underscore}_sign_out", { :controller => "#{singular_table_name.underscore}_sessions", :action => "remove_cookies", :via => "get"}) - - # Route for creating account into database - - match("/post_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "create", :via => "post" }) - - # Route for editing account - - match("/edit_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "edit_registration_form", :via => "get"}) - - match("/patch_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "update", :via => "post"}) - - # Route for removing an account - - match("/cancel_#{singular_table_name.underscore}_account", { :controller => "#{plural_table_name.underscore}", :action => "destroy", :via => "get"}) + # DELETE RECORD + get("/cancel_#{singular_table_name.underscore}_account", { :controller => "#{plural_table_name.underscore}", :action => "destroy" }) + # ------------------------------ + # SIGN IN FORM + get("/#{singular_table_name.underscore}_sign_in", { :controller => "#{singular_table_name.underscore}_sessions", :action => "new_session_form" }) + # AUTHENTICATE AND STORE COOKIE + post("/#{singular_table_name.underscore}_verify_credentials", { :controller => "#{singular_table_name.underscore}_sessions", :action => "create_cookie" }) + + # SIGN OUT + get("/#{singular_table_name.underscore}_sign_out", { :controller => "#{singular_table_name.underscore}_sessions", :action => "destroy_cookies" }) + #------------------------------ RUBY end @@ -100,7 +97,8 @@ def authentication_helpers application_controller <<-RUBY.gsub(/^ /, "") before_action(:load_current_#{singular_table_name.underscore}) - before_action(:force_#{singular_table_name.underscore}_sign_in) + + # before_action(:force_#{singular_table_name.underscore}_sign_in) def load_current_#{singular_table_name.underscore} the_id = session.fetch(:#{singular_table_name.underscore}_id) diff --git a/lib/generators/draft/account/templates/controllers/controller.rb b/lib/generators/draft/account/templates/controllers/controller.rb index e39a6249..025e0e10 100644 --- a/lib/generators/draft/account/templates/controllers/controller.rb +++ b/lib/generators/draft/account/templates/controllers/controller.rb @@ -1,5 +1,5 @@ class <%= class_name.pluralize %>Controller < ApplicationController - skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:new_registration_form, :create] }) + # skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:new_registration_form, :create] }) def new_registration_form render({ :template => "<%=singular_table_name.underscore %>_sessions/sign_up.html.erb" }) @@ -9,12 +9,12 @@ def create @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_query", false) + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) <% elsif attribute.column_name != "password_digest" -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_query") + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") <% else -%> - @<%= singular_table_name.underscore %>.password = params.fetch("password_from_query") - @<%= singular_table_name.underscore %>.password_confirmation = params.fetch("password_confirmation_from_query") + @<%= singular_table_name.underscore %>.password = params.fetch("query_password") + @<%= singular_table_name.underscore %>.password_confirmation = params.fetch("query_password_confirmation") <% end -%> <% end -%> @@ -37,12 +37,12 @@ def update @<%= singular_table_name.underscore %> = @current_<%= singular_table_name.underscore %> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_query", false) + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) <% elsif attribute.column_name != "password_digest" -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_query") + @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") <% else -%> - @<%= singular_table_name.underscore %>.password = params.fetch("password_from_query") - @<%= singular_table_name.underscore %>.password_confirmation = params.fetch("password_confirmation_from_query") + @<%= singular_table_name.underscore %>.password = params.fetch("query_password") + @<%= singular_table_name.underscore %>.password_confirmation = params.fetch("query_password_confirmation") <% end -%> <% end -%> diff --git a/lib/generators/draft/account/templates/controllers/sessions_controller.rb b/lib/generators/draft/account/templates/controllers/sessions_controller.rb index 1325ac49..83ae6360 100644 --- a/lib/generators/draft/account/templates/controllers/sessions_controller.rb +++ b/lib/generators/draft/account/templates/controllers/sessions_controller.rb @@ -1,31 +1,31 @@ class <%= class_name.singularize %>SessionsController < ApplicationController - skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:new_session_form, :add_cookie] }) + # skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:new_session_form, :create_cookie] }) def new_session_form - render({ :template => "<%=singular_table_name.underscore %>_sessions/sign_in.html.erb" }) + render({ :template => "<%= singular_table_name.underscore %>_sessions/sign_in.html.erb" }) end - def add_cookie - <%=singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :email => params.fetch("email_from_query") }).at(0) + def create_cookie + <%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :email => params.fetch("query_email") }).at(0) - the_supplied_password = params.fetch("password_from_query") + the_supplied_password = params.fetch("query_password") - if <%=singular_table_name.underscore %> != nil - are_they_legit = <%=singular_table_name.underscore %>.authenticate(the_supplied_password) + if <%= singular_table_name.underscore %> != nil + are_they_legit = <%= singular_table_name.underscore %>.authenticate(the_supplied_password) if are_they_legit == false - redirect_to("/<%=singular_table_name.underscore %>_sign_in", { :alert => "Password incorrect." }) + redirect_to("/<%= singular_table_name.underscore %>_sign_in", { :alert => "Incorrect password." }) else - session.store(:<%=singular_table_name.underscore %>_id, <%=singular_table_name.underscore %>.id) + session.store(:<%= singular_table_name.underscore %>_id, <%=singular_table_name.underscore %>.id) redirect_to("/", { :notice => "Signed in successfully." }) end else - redirect_to("/<%=singular_table_name.underscore %>_sign_in", { :alert => "There's no <%=singular_table_name.underscore %> account with that email address." }) + redirect_to("/<%= singular_table_name.underscore %>_sign_in", { :alert => "No <%= singular_table_name.underscore %> with that email address." }) end end - def remove_cookies + def destroy_cookies reset_session redirect_to("/", { :notice => "Signed out successfully." }) diff --git a/lib/generators/draft/account/templates/views/edit_profile.html.erb b/lib/generators/draft/account/templates/views/edit_profile.html.erb index 32bc62e3..7221501c 100644 --- a/lib/generators/draft/account/templates/views/edit_profile.html.erb +++ b/lib/generators/draft/account/templates/views/edit_profile.html.erb @@ -4,17 +4,17 @@
-
+ <% attributes.each do |attribute| -%> <% if attribute.column_name != "password_digest" -%>
<% if attribute.field_type == :text_area -%> - + <% elsif attribute.field_type == :check_box -%> - + <% else -%> - + <% end -%>
<% end -%> @@ -22,12 +22,12 @@
- +
- +
diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index ddd13472..2e538572 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -89,7 +89,7 @@ <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%>
- .<%= attribute.column_name %> %>> + .<%= attribute.column_name %> %>> @@ -102,18 +102,18 @@ <% if attribute.field_type == :text_area -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> - <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%> - + <% else -%> - + <% end -%>
From e8d77c127088a07d17848ba47a0241a3b585a258 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 2 Jun 2020 10:30:00 -0500 Subject: [PATCH 35/47] Re-organizing draft:account Putting all of the draft:account actions into one controller, ____AuthenticationController (I believe that this is the pattern Devise follows?); to make it easier to see in one place and understand, and skip the :force____sign_in before_action for signing up/in a person opts in to that. I believe the older approach grew organically out of adding authentication to an existing tutorial project while I was recording a video (photogram-gui => photogram-signin) and then we codified it in this gem. I also replace `session.fetch()` with `session[]` temporarily because Rails has added `fetch` itself; our monkeypatch now has different behavior than the canonical method. After this quarter, we'll go back to `.fetch`. In preparation for that, I replace `ActiveRecord::Relation#at(0)` with `.first` so that the gem will ultimately be able to be used without our monkeypatches. --- .../draft/account/account_generator.rb | 42 +++++++-------- ...roller.rb => authentication_controller.rb} | 53 +++++++++++++++---- .../controllers/sessions_controller.rb | 34 ------------ .../edit_profile.html.erb | 0 .../edit_profile_with_errors.html.erb | 0 .../sign_in.html.erb | 0 .../sign_up.html.erb | 0 7 files changed, 60 insertions(+), 69 deletions(-) rename lib/generators/draft/account/templates/controllers/{controller.rb => authentication_controller.rb} (51%) delete mode 100644 lib/generators/draft/account/templates/controllers/sessions_controller.rb rename lib/generators/draft/account/templates/views/{ => authentication}/edit_profile.html.erb (100%) rename lib/generators/draft/account/templates/views/{ => authentication}/edit_profile_with_errors.html.erb (100%) rename lib/generators/draft/account/templates/views/{sessions => authentication}/sign_in.html.erb (100%) rename lib/generators/draft/account/templates/views/{sessions => authentication}/sign_up.html.erb (100%) diff --git a/lib/generators/draft/account/account_generator.rb b/lib/generators/draft/account/account_generator.rb index c566c024..45fda601 100644 --- a/lib/generators/draft/account/account_generator.rb +++ b/lib/generators/draft/account/account_generator.rb @@ -34,24 +34,17 @@ def generate_before_actions end def generate_controller - template "controllers/sessions_controller.rb", "app/controllers/#{singular_table_name.underscore}_sessions_controller.rb" - template "controllers/controller.rb", "app/controllers/#{plural_table_name.underscore}_controller.rb" + template "controllers/authentication_controller.rb", "app/controllers/#{singular_table_name.underscore}_authentication_controller.rb" end def create_root_folder - empty_directory File.join("app/views", "#{singular_table_name.underscore}_sessions") - empty_directory File.join("app/views", "#{plural_table_name.underscore}") + empty_directory File.join("app/views", "#{singular_table_name.underscore}_authentication") end def generate_view_files - available_views.select{|filename| filename.include?("sign")}.each do |view| - filename = view_sessions_filename_with_extensions(view) - template filename, File.join("app/views/#{singular_table_name.underscore}_sessions", File.basename(filename)) - end - - available_views.reject{|filename| filename.include?("sign")}.each do |view| - filename = view_filename_with_extensions(view) - template filename, File.join("app/views/#{plural_table_name.underscore}", File.basename(filename)) + available_views.each do |view| + filename = view_authentication_filename_with_extensions(view) + template filename, File.join("app/views/#{singular_table_name.underscore}_authentication", File.basename(filename)) end end @@ -65,27 +58,27 @@ def authentication_routes # Routes for the #{singular_table_name.humanize} account: # SIGN UP FORM - get("/#{singular_table_name.underscore}_sign_up", { :controller => "#{plural_table_name.underscore}", :action => "new_registration_form" }) + get("/#{singular_table_name.underscore}_sign_up", { :controller => "#{singular_table_name.underscore}_authentication", :action => "sign_up_form" }) # CREATE RECORD - post("/insert_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "create" }) + post("/insert_#{singular_table_name.underscore}", { :controller => "#{singular_table_name.underscore}_authentication", :action => "create" }) # EDIT PROFILE FORM - get("/edit_#{singular_table_name.underscore}_profile", { :controller => "#{plural_table_name.underscore}", :action => "edit_registration_form" }) + get("/edit_#{singular_table_name.underscore}_profile", { :controller => "#{singular_table_name.underscore}_authentication", :action => "edit_profile_form" }) # UPDATE RECORD - post("/modify_#{singular_table_name.underscore}", { :controller => "#{plural_table_name.underscore}", :action => "update" }) + post("/modify_#{singular_table_name.underscore}", { :controller => "#{singular_table_name.underscore}_authentication", :action => "update" }) # DELETE RECORD - get("/cancel_#{singular_table_name.underscore}_account", { :controller => "#{plural_table_name.underscore}", :action => "destroy" }) + get("/cancel_#{singular_table_name.underscore}_account", { :controller => "#{singular_table_name.underscore}_authentication", :action => "destroy" }) # ------------------------------ # SIGN IN FORM - get("/#{singular_table_name.underscore}_sign_in", { :controller => "#{singular_table_name.underscore}_sessions", :action => "new_session_form" }) + get("/#{singular_table_name.underscore}_sign_in", { :controller => "#{singular_table_name.underscore}_authentication", :action => "sign_in_form" }) # AUTHENTICATE AND STORE COOKIE - post("/#{singular_table_name.underscore}_verify_credentials", { :controller => "#{singular_table_name.underscore}_sessions", :action => "create_cookie" }) + post("/#{singular_table_name.underscore}_verify_credentials", { :controller => "#{singular_table_name.underscore}_authentication", :action => "create_cookie" }) # SIGN OUT - get("/#{singular_table_name.underscore}_sign_out", { :controller => "#{singular_table_name.underscore}_sessions", :action => "destroy_cookies" }) + get("/#{singular_table_name.underscore}_sign_out", { :controller => "#{singular_table_name.underscore}_authentication", :action => "destroy_cookies" }) #------------------------------ RUBY @@ -98,11 +91,12 @@ def authentication_helpers before_action(:load_current_#{singular_table_name.underscore}) + # Uncomment this if you want to force #{plural_table_name} to sign in before any other actions # before_action(:force_#{singular_table_name.underscore}_sign_in) def load_current_#{singular_table_name.underscore} - the_id = session.fetch(:#{singular_table_name.underscore}_id) - @current_#{singular_table_name.underscore} = #{class_name.singularize}.where({ :id => the_id }).at(0) + the_id = session[:#{singular_table_name.underscore}_id] + @current_#{singular_table_name.underscore} = #{class_name.singularize}.where({ :id => the_id }).first end def force_#{singular_table_name.underscore}_sign_in @@ -152,9 +146,9 @@ def view_filename_with_extensions(name) filename end - def view_sessions_filename_with_extensions(name) + def view_authentication_filename_with_extensions(name) filename = [name, :html, :erb].compact.join(".") - folders = ["views", "sessions"] + folders = ["views", "authentication"] filename = File.join(folders, filename) if folders.any? filename end diff --git a/lib/generators/draft/account/templates/controllers/controller.rb b/lib/generators/draft/account/templates/controllers/authentication_controller.rb similarity index 51% rename from lib/generators/draft/account/templates/controllers/controller.rb rename to lib/generators/draft/account/templates/controllers/authentication_controller.rb index 025e0e10..4783f620 100644 --- a/lib/generators/draft/account/templates/controllers/controller.rb +++ b/lib/generators/draft/account/templates/controllers/authentication_controller.rb @@ -1,8 +1,39 @@ -class <%= class_name.pluralize %>Controller < ApplicationController - # skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:new_registration_form, :create] }) - - def new_registration_form - render({ :template => "<%=singular_table_name.underscore %>_sessions/sign_up.html.erb" }) +class <%= class_name.singularize %>AuthenticationController < ApplicationController + # Uncomment this if you want to force <%= plural_table_name %> to sign in before any other actions + # skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:sign_up_form, :create, :sign_in_form, :create_cookie] }) + + def sign_in_form + render({ :template => "<%= singular_table_name.underscore %>_authentication/sign_in.html.erb" }) + end + + def create_cookie + <%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :email => params.fetch("query_email") }).first + + the_supplied_password = params.fetch("query_password") + + if <%= singular_table_name.underscore %> != nil + are_they_legit = <%= singular_table_name.underscore %>.authenticate(the_supplied_password) + + if are_they_legit == false + redirect_to("/<%= singular_table_name.underscore %>_sign_in", { :alert => "Incorrect password." }) + else + session[:<%= singular_table_name.underscore %>_id] = <%= singular_table_name.underscore %>.id + + redirect_to("/", { :notice => "Signed in successfully." }) + end + else + redirect_to("/<%= singular_table_name.underscore %>_sign_in", { :alert => "No <%= singular_table_name.underscore %> with that email address." }) + end + end + + def destroy_cookies + reset_session + + redirect_to("/", { :notice => "Signed out successfully." }) + end + + def sign_up_form + render({ :template => "<%= singular_table_name.underscore %>_authentication/sign_up.html.erb" }) end def create @@ -21,16 +52,16 @@ def create save_status = @<%= singular_table_name.underscore %>.save if save_status == true - session.store(:<%= singular_table_name.underscore %>_id, @<%= singular_table_name.underscore %>.id) + session[:<%= singular_table_name.underscore %>_id] = @<%= singular_table_name.underscore %>.id redirect_to("/", { :notice => "<%= singular_table_name.humanize %> account created successfully."}) else - redirect_to("/<%=singular_table_name.underscore %>_sign_up", { :alert => "<%= singular_table_name.humanize %> account failed to create successfully."}) + redirect_to("/<%= singular_table_name.underscore %>_sign_up", { :alert => "<%= singular_table_name.humanize %> account failed to create successfully."}) end end - def edit_registration_form - render({ :template => "<%= plural_table_name.underscore %>/edit_profile.html.erb" }) + def edit_profile_form + render({ :template => "<%= singular_table_name.underscore %>_authentication/edit_profile.html.erb" }) end def update @@ -51,7 +82,7 @@ def update redirect_to("/", { :notice => "<%= singular_table_name.humanize %> account updated successfully."}) else - render({ :template => "<%= plural_table_name.underscore %>/edit_profile_with_errors.html.erb" }) + render({ :template => "<%= singular_table_name.underscore %>_authentication/edit_profile_with_errors.html.erb" }) end end @@ -61,5 +92,5 @@ def destroy redirect_to("/", { :notice => "<%= class_name.singularize %> account cancelled" }) end - + end diff --git a/lib/generators/draft/account/templates/controllers/sessions_controller.rb b/lib/generators/draft/account/templates/controllers/sessions_controller.rb deleted file mode 100644 index 83ae6360..00000000 --- a/lib/generators/draft/account/templates/controllers/sessions_controller.rb +++ /dev/null @@ -1,34 +0,0 @@ -class <%= class_name.singularize %>SessionsController < ApplicationController - # skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:new_session_form, :create_cookie] }) - - def new_session_form - render({ :template => "<%= singular_table_name.underscore %>_sessions/sign_in.html.erb" }) - end - - def create_cookie - <%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :email => params.fetch("query_email") }).at(0) - - the_supplied_password = params.fetch("query_password") - - if <%= singular_table_name.underscore %> != nil - are_they_legit = <%= singular_table_name.underscore %>.authenticate(the_supplied_password) - - if are_they_legit == false - redirect_to("/<%= singular_table_name.underscore %>_sign_in", { :alert => "Incorrect password." }) - else - session.store(:<%= singular_table_name.underscore %>_id, <%=singular_table_name.underscore %>.id) - - redirect_to("/", { :notice => "Signed in successfully." }) - end - else - redirect_to("/<%= singular_table_name.underscore %>_sign_in", { :alert => "No <%= singular_table_name.underscore %> with that email address." }) - end - end - - def destroy_cookies - reset_session - - redirect_to("/", { :notice => "Signed out successfully." }) - end - -end diff --git a/lib/generators/draft/account/templates/views/edit_profile.html.erb b/lib/generators/draft/account/templates/views/authentication/edit_profile.html.erb similarity index 100% rename from lib/generators/draft/account/templates/views/edit_profile.html.erb rename to lib/generators/draft/account/templates/views/authentication/edit_profile.html.erb diff --git a/lib/generators/draft/account/templates/views/edit_profile_with_errors.html.erb b/lib/generators/draft/account/templates/views/authentication/edit_profile_with_errors.html.erb similarity index 100% rename from lib/generators/draft/account/templates/views/edit_profile_with_errors.html.erb rename to lib/generators/draft/account/templates/views/authentication/edit_profile_with_errors.html.erb diff --git a/lib/generators/draft/account/templates/views/sessions/sign_in.html.erb b/lib/generators/draft/account/templates/views/authentication/sign_in.html.erb similarity index 100% rename from lib/generators/draft/account/templates/views/sessions/sign_in.html.erb rename to lib/generators/draft/account/templates/views/authentication/sign_in.html.erb diff --git a/lib/generators/draft/account/templates/views/sessions/sign_up.html.erb b/lib/generators/draft/account/templates/views/authentication/sign_up.html.erb similarity index 100% rename from lib/generators/draft/account/templates/views/sessions/sign_up.html.erb rename to lib/generators/draft/account/templates/views/authentication/sign_up.html.erb From 0e3e763741e902c523a3e2922572ad47c1d72848 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Tue, 2 Jun 2020 13:19:31 -0500 Subject: [PATCH 36/47] Comment out javascript pack tag --- lib/generators/draft/layout/templates/layout.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/layout/templates/layout.html.erb b/lib/generators/draft/layout/templates/layout.html.erb index 0bd850ee..1b0c07dc 100644 --- a/lib/generators/draft/layout/templates/layout.html.erb +++ b/lib/generators/draft/layout/templates/layout.html.erb @@ -16,7 +16,7 @@ <%%= stylesheet_link_tag 'application', media: 'all' %> - <%%= javascript_pack_tag 'application' %> + <%%# javascript_pack_tag 'application' %> <%%= render "shared/cdn_assets" %> From 2714b2507753af7a81310f012fb6af43f7fe519c Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Fri, 5 Jun 2020 10:07:32 -0500 Subject: [PATCH 37/47] Prepopulate checkbox on edit account forms --- .../templates/views/authentication/edit_profile.html.erb | 2 +- .../views/authentication/edit_profile_with_errors.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/account/templates/views/authentication/edit_profile.html.erb b/lib/generators/draft/account/templates/views/authentication/edit_profile.html.erb index 7221501c..79844bc8 100644 --- a/lib/generators/draft/account/templates/views/authentication/edit_profile.html.erb +++ b/lib/generators/draft/account/templates/views/authentication/edit_profile.html.erb @@ -12,7 +12,7 @@ <% if attribute.field_type == :text_area -%> <% elsif attribute.field_type == :check_box -%> - + .<%= attribute.column_name %> %>> <% else -%> <% end -%> diff --git a/lib/generators/draft/account/templates/views/authentication/edit_profile_with_errors.html.erb b/lib/generators/draft/account/templates/views/authentication/edit_profile_with_errors.html.erb index c1ff83ab..2b7dfc87 100644 --- a/lib/generators/draft/account/templates/views/authentication/edit_profile_with_errors.html.erb +++ b/lib/generators/draft/account/templates/views/authentication/edit_profile_with_errors.html.erb @@ -19,7 +19,7 @@ <% if attribute.field_type == :text_area %> <% elsif attribute.field_type == :check_box %> - + .<%= attribute.column_name %> %>> <% else %> <% end %> From 1bea3b3608c3b25c8bf3919256bfe4a0aece841f Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Tue, 4 Aug 2020 02:40:48 -0500 Subject: [PATCH 38/47] Update controller.rb --- .../draft/resource/templates/controllers/controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 9b7da96a..ab1816ce 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -7,7 +7,7 @@ def index def show the_id = params.fetch("path_id") - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({:id => the_id }).at(0) + @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) render({ :template => "<%= plural_table_name.underscore %>/show.html.erb" }) end From 50a4a7bc6b748852d6d56abe8ca023a76fdd1f2a Mon Sep 17 00:00:00 2001 From: Patrick McKernin Date: Thu, 6 Aug 2020 20:17:48 -0500 Subject: [PATCH 39/47] This commit resolves issue #86. The resource variables were changed to be more current with our current teachings in class. The singluar variables were moved to @the_ and the plural were changed to @list_of. We used the gem indefinite_article which helped with the naming of the block variables in the index page. This gem needed to be initalized in three different places. wip added indefintite_article gem wip wip wip wip wip wip wip Require gem in resource_generator.rb update gemspec removed require from resource generator wip" " added indefinitize to all remaining block variables added one more @the_ to the create action added @the_ to update action added @the_ to the redirect in update forgot a _ removed require from resource_generator.rb needs to have require 'indefinite_article' in the resource generator.rb file removed git_source from the gemfile removed a space from gemfile changed the single quotes to double and removed the extra space at the beginning of the index file --- Gemfile | 1 + draft_generators.gemspec | 1 + lib/draft_generators.rb | 1 + .../draft/resource/resource_generator.rb | 2 + .../templates/controllers/controller.rb | 38 +++++++++---------- .../resource/templates/views/index.html.erb | 28 +++++++------- .../resource/templates/views/show.html.erb | 30 +++++++-------- 7 files changed, 53 insertions(+), 48 deletions(-) diff --git a/Gemfile b/Gemfile index 7293f830..183712ab 100644 --- a/Gemfile +++ b/Gemfile @@ -13,4 +13,5 @@ group :development do gem "simplecov", ">= 0" end +gem 'indefinite_article' gem 'devise' diff --git a/draft_generators.gemspec b/draft_generators.gemspec index ea37250e..88a8f55d 100644 --- a/draft_generators.gemspec +++ b/draft_generators.gemspec @@ -95,6 +95,7 @@ Gem::Specification.new do |s| if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q.freeze, [">= 0"]) + s.add_runtime_dependency(%q.freeze, [">= 0"]) s.add_development_dependency(%q.freeze, ["~> 3.5.0"]) s.add_development_dependency(%q.freeze, ["~> 3.12"]) s.add_development_dependency(%q.freeze, ["~> 1.0"]) diff --git a/lib/draft_generators.rb b/lib/draft_generators.rb index 81eb0e06..83d63e63 100644 --- a/lib/draft_generators.rb +++ b/lib/draft_generators.rb @@ -3,6 +3,7 @@ require "devise_customization_service" require "rails_tag_service" require "devise" +require "indefinite_article" module DraftGenerators end diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index db288240..c5e3366b 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -1,3 +1,5 @@ +require 'indefinite_article' + module Draft class ResourceGenerator < Rails::Generators::NamedBase source_root File.expand_path("../templates", __FILE__) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index ab1816ce..78491d8b 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -1,36 +1,36 @@ class <%= plural_table_name.camelize %>Controller < ApplicationController def index - @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all.order({ :created_at => :desc }) + @list_of_<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all.order({ :created_at => :desc }) render({ :template => "<%= plural_table_name.underscore %>/index.html.erb" }) end def show the_id = params.fetch("path_id") - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) + @the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) render({ :template => "<%= plural_table_name.underscore %>/show.html.erb" }) end def create - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new + @the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) + @the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) <% else -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") + @the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") <% end -%> <% end -%> <% unless skip_validation_alerts? -%> - if @<%= singular_table_name.underscore %>.valid? - @<%= singular_table_name.underscore %>.save + if @the_<%= singular_table_name.underscore %>.valid? + @the_<%= singular_table_name.underscore %>.save redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> created successfully." }) else redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> failed to create successfully." }) end <% else -%> - @<%= singular_table_name.underscore %>.save + @the_<%= singular_table_name.underscore %>.save <% unless skip_redirect? -%> redirect_to("/<%= @plural_table_name.underscore %>") @@ -44,28 +44,28 @@ def create def update the_id = params.fetch("path_id") - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) + @the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) + @the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) <% else -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") + @the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") <% end -%> <% end -%> <% unless skip_validation_alerts? -%> - if @<%= singular_table_name.underscore %>.valid? - @<%= singular_table_name.underscore %>.save - redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", { :notice => "<%= singular_table_name.humanize %> updated successfully."} ) + if @the_<%= singular_table_name.underscore %>.valid? + @the_<%= singular_table_name.underscore %>.save + redirect_to("/<%= @plural_table_name.underscore %>/#{@the_<%= singular_table_name.underscore %>.id}", { :notice => "<%= singular_table_name.humanize %> updated successfully."} ) else - redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", { :alert => "<%= singular_table_name.humanize %> failed to update successfully." }) + redirect_to("/<%= @plural_table_name.underscore %>/#{@the_<%= singular_table_name.underscore %>.id}", { :alert => "<%= singular_table_name.humanize %> failed to update successfully." }) end <% else -%> - @<%= singular_table_name.underscore %>.save + @the_<%= singular_table_name.underscore %>.save <% unless skip_redirect? -%> - redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}") + redirect_to("/<%= @plural_table_name.underscore %>/#{@the_<%= singular_table_name.underscore %>.id}") <% else -%> render({ :template => "<%= plural_table_name.underscore %>/show.html.erb" }) <% end -%> @@ -74,9 +74,9 @@ def update def destroy the_id = params.fetch("path_id") - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) + @the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) - @<%= singular_table_name.underscore %>.destroy + @the_<%= singular_table_name.underscore %>.destroy <% unless skip_validation_alerts? -%> redirect_to("/<%= @plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> deleted successfully."} ) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index fa0ba553..bd5af778 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -92,50 +92,50 @@ - <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %> + <%% @list_of_<%= plural_table_name %>.each do |<%= singular_table_name.indefinitize.gsub(" ", "_") %>| %> <% if with_sentinels? -%> - + <% end -%> - <%%= <%= singular_table_name %>.id %> + <%%= <%= singular_table_name.indefinitize.gsub(" ", "_") %>.id %> <% if with_sentinels? -%> - + <% end -%> <% attributes.each do |attribute| -%> <% if with_sentinels? -%> - + <% end -%> - <%%= <%= singular_table_name %>.<%= attribute.column_name %> %> + <%%= <%= singular_table_name.indefinitize.gsub(" ", "_") %>.<%= attribute.column_name %> %> <% if with_sentinels? -%> - + <% end -%> <% end -%> <% if with_sentinels? -%> - + <% end -%> - <%%= time_ago_in_words(<%= singular_table_name %>.created_at) %> ago + <%%= time_ago_in_words(<%= singular_table_name.indefinitize.gsub(" ", "_") %>.created_at) %> ago <% if with_sentinels? -%> - + - + <% end -%> - <%%= time_ago_in_words(<%= singular_table_name %>.updated_at) %> ago + <%%= time_ago_in_words(<%= singular_table_name.indefinitize.gsub(" ", "_") %>.updated_at) %> ago <% if with_sentinels? -%> - + <% end -%> - + .id %>"> Show details diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 2e538572..7496c6df 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -1,7 +1,7 @@

- <%= singular_table_name.humanize %> #<%%= @<%= singular_table_name %>.id %> details + <%= singular_table_name.humanize %> #<%%= @the_<%= singular_table_name %>.id %> details

@@ -16,7 +16,7 @@ <% end -%> @@ -32,13 +32,13 @@ <%= attribute.human_name %>
<% if with_sentinels? -%> - + <% end -%>
- <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <%%= @the_<%= singular_table_name %>.<%= attribute.column_name %> %>
<% if with_sentinels? -%> - + <% end -%> <% end -%> @@ -49,7 +49,7 @@ <% end -%>
- <%%= time_ago_in_words(@<%= singular_table_name %>.created_at) %> ago + <%%= time_ago_in_words(@the_<%= singular_table_name %>.created_at) %> ago
<% if with_sentinels? -%> @@ -62,7 +62,7 @@ <% end -%>
- <%%= time_ago_in_words(@<%= singular_table_name %>.updated_at) %> ago + <%%= time_ago_in_words(@the_<%= singular_table_name %>.updated_at) %> ago
<% if with_sentinels? -%> @@ -85,11 +85,11 @@ Edit <%= singular_table_name.humanize.downcase %> - method="post" <% end -%>> + method="post" <% end -%>> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%>
- .<%= attribute.column_name %> %>> + .<%= attribute.column_name %> %>> @@ -102,18 +102,18 @@ <% if attribute.field_type == :text_area -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> + class="form-control" value="<%%= @the_<%= singular_table_name %>.<%= attribute.column_name %> %>"> <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%> - + <% else -%> - + <% end -%>
From fb4cb871d461b0fe422dd3d93d6537041b70b0c5 Mon Sep 17 00:00:00 2001 From: Patrick McKernin Date: Tue, 11 Aug 2020 15:32:56 -0500 Subject: [PATCH 40/47] Using the new style for summer 2020, I removed the instance variables from the draft:resource controller. I replaced these with regular variables because they were not being brought to a html page. This resovles issues #93. --- .../templates/controllers/controller.rb | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 78491d8b..9aac7e9a 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -13,24 +13,24 @@ def show end def create - @the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new + the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> - @the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) + the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) <% else -%> - @the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") + the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") <% end -%> <% end -%> <% unless skip_validation_alerts? -%> - if @the_<%= singular_table_name.underscore %>.valid? - @the_<%= singular_table_name.underscore %>.save + if the_<%= singular_table_name.underscore %>.valid? + the_<%= singular_table_name.underscore %>.save redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> created successfully." }) else redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> failed to create successfully." }) end <% else -%> - @the_<%= singular_table_name.underscore %>.save + the_<%= singular_table_name.underscore %>.save <% unless skip_redirect? -%> redirect_to("/<%= @plural_table_name.underscore %>") @@ -44,28 +44,28 @@ def create def update the_id = params.fetch("path_id") - @the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) + the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> - @the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) + the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>", false) <% else -%> - @the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") + the_<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params.fetch("query_<%= attribute.column_name %>") <% end -%> <% end -%> <% unless skip_validation_alerts? -%> - if @the_<%= singular_table_name.underscore %>.valid? - @the_<%= singular_table_name.underscore %>.save - redirect_to("/<%= @plural_table_name.underscore %>/#{@the_<%= singular_table_name.underscore %>.id}", { :notice => "<%= singular_table_name.humanize %> updated successfully."} ) + if the_<%= singular_table_name.underscore %>.valid? + the_<%= singular_table_name.underscore %>.save + redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}", { :notice => "<%= singular_table_name.humanize %> updated successfully."} ) else - redirect_to("/<%= @plural_table_name.underscore %>/#{@the_<%= singular_table_name.underscore %>.id}", { :alert => "<%= singular_table_name.humanize %> failed to update successfully." }) + redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}", { :alert => "<%= singular_table_name.humanize %> failed to update successfully." }) end <% else -%> - @the_<%= singular_table_name.underscore %>.save + the_<%= singular_table_name.underscore %>.save <% unless skip_redirect? -%> - redirect_to("/<%= @plural_table_name.underscore %>/#{@the_<%= singular_table_name.underscore %>.id}") + redirect_to("/<%= plural_table_name.underscore %>/#{the_<%= singular_table_name.underscore %>.id}") <% else -%> render({ :template => "<%= plural_table_name.underscore %>/show.html.erb" }) <% end -%> @@ -74,19 +74,19 @@ def update def destroy the_id = params.fetch("path_id") - @the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) + the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) - @the_<%= singular_table_name.underscore %>.destroy + the_<%= singular_table_name.underscore %>.destroy <% unless skip_validation_alerts? -%> - redirect_to("/<%= @plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> deleted successfully."} ) + redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> deleted successfully."} ) <% else -%> <% unless skip_redirect? -%> - redirect_to("/<%= @plural_table_name.underscore %>") + redirect_to("/<%= plural_table_name.underscore %>") <% else -%> @remaining_count = <%= class_name.singularize %>.count - redirect_to("/<%= @plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> deleted successfully."} ) + redirect_to("/<%= plural_table_name.underscore %>", { :notice => "<%= singular_table_name.humanize %> deleted successfully."} ) <% end -%> <% end -%> end From 671e66bf531d4baf3f49cb6bcc4f5803d20ae1b5 Mon Sep 17 00:00:00 2001 From: Patrick McKernin Date: Mon, 10 Aug 2020 14:59:01 -0500 Subject: [PATCH 41/47] Changed the query style to match our teaching in the summer 2020 quarter. This resolves #92 --- .../draft/resource/templates/controllers/controller.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 9aac7e9a..a7766f4f 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -1,13 +1,18 @@ class <%= plural_table_name.camelize %>Controller < ApplicationController def index - @list_of_<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all.order({ :created_at => :desc }) + matching_<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all + + @list_of_<%= plural_table_name.underscore %> = matching_<%= plural_table_name.underscore %>.order({ :created_at => :desc }) render({ :template => "<%= plural_table_name.underscore %>/index.html.erb" }) end def show the_id = params.fetch("path_id") - @the_<%= singular_table_name.underscore %> = <%= class_name.singularize %>.where({ :id => the_id }).at(0) + + matching_<%= plural_table_name.underscore.downcase %> = <%= class_name.singularize %>.where({ :id => the_id }) + + @the_<%= singular_table_name.underscore %> = matching_<%= plural_table_name.underscore.downcase %>.at(0) render({ :template => "<%= plural_table_name.underscore %>/show.html.erb" }) end From aff224a3220764bea1919b7d00bc7c8df58560c1 Mon Sep 17 00:00:00 2001 From: Patrick McKernin Date: Fri, 7 Aug 2020 14:32:13 -0500 Subject: [PATCH 42/47] Removed bootstrap from winter-2020. Resolves #89 --- .../views/association_new_form.html.erb | 12 +++--- .../templates/views/edit_form.html.erb | 14 +++--- .../views/edit_form_with_errors.html.erb | 16 +++---- .../resource/templates/views/index.html.erb | 36 ++++++++-------- .../templates/views/new_form.html.erb | 14 +++--- .../views/new_form_with_errors.html.erb | 16 +++---- .../resource/templates/views/show.html.erb | 43 ++++++++++--------- 7 files changed, 76 insertions(+), 75 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/association_new_form.html.erb b/lib/generators/draft/resource/templates/views/association_new_form.html.erb index 26cdfe6c..b089dced 100644 --- a/lib/generators/draft/resource/templates/views/association_new_form.html.erb +++ b/lib/generators/draft/resource/templates/views/association_new_form.html.erb @@ -19,20 +19,20 @@ <% end -%> <% elsif attribute.field_type == :check_box -%> -
+
<% if with_sentinels? -%> <% end -%> - <%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%>> + <%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%>> <% if with_sentinels? -%> <% end -%>
<% else -%> -
+
@@ -41,7 +41,7 @@ <% if with_sentinels? -%> <% end -%> - + <% if with_sentinels? -%> <% end -%> @@ -49,7 +49,7 @@ <% if with_sentinels? -%> <% end -%> - value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>> + value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>> <% if with_sentinels? -%> <% end -%> @@ -61,7 +61,7 @@ <% end -%> <% end -%> - diff --git a/lib/generators/draft/resource/templates/views/edit_form.html.erb b/lib/generators/draft/resource/templates/views/edit_form.html.erb index 4b29fac4..ee86d0e3 100644 --- a/lib/generators/draft/resource/templates/views/edit_form.html.erb +++ b/lib/generators/draft/resource/templates/views/edit_form.html.erb @@ -17,21 +17,21 @@ <% end -%> <% if attribute.field_type == :check_box -%> -
+
<% if with_sentinels? -%> <% end -%> - .<%= attribute.column_name %> %>> + .<%= attribute.column_name %> %>> <% if with_sentinels? -%> <% end -%> -
<% else -%> -
+
@@ -40,7 +40,7 @@ <% if with_sentinels? -%> <% end -%> - + <% if with_sentinels? -%> <% end -%> @@ -48,7 +48,7 @@ <% if with_sentinels? -%> <% end -%> - + <% if with_sentinels? -%> <% end -%> @@ -60,7 +60,7 @@ <% end -%> <% end -%> - diff --git a/lib/generators/draft/resource/templates/views/edit_form_with_errors.html.erb b/lib/generators/draft/resource/templates/views/edit_form_with_errors.html.erb index 1f63ca02..1e3053f1 100644 --- a/lib/generators/draft/resource/templates/views/edit_form_with_errors.html.erb +++ b/lib/generators/draft/resource/templates/views/edit_form_with_errors.html.erb @@ -4,7 +4,7 @@ <% end -%> <%% if @<%= singular_table_name %>.errors.any? %> <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %> -
+
<%%= message %>
<%% end %> @@ -30,21 +30,21 @@ <% end -%> <% if attribute.field_type == :check_box -%> -
+
<% if with_sentinels? -%> <% end -%> - .<%= attribute.column_name %> %>> + .<%= attribute.column_name %> %>> <% if with_sentinels? -%> <% end -%> -
<% else -%> -
+
@@ -53,7 +53,7 @@ <% if with_sentinels? -%> <% end -%> - + <% if with_sentinels? -%> <% end -%> @@ -61,7 +61,7 @@ <% if with_sentinels? -%> <% end -%> - + <% if with_sentinels? -%> <% end -%> @@ -73,7 +73,7 @@ <% end -%> <% end -%> - diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index bd5af778..b153d823 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -1,5 +1,5 @@ -
-
+
+

List of all <%= plural_table_name.humanize.downcase %>

@@ -8,8 +8,8 @@
-
-
+
+

Add a new <%= singular_table_name.humanize.downcase %>

@@ -17,36 +17,36 @@
method="post"<% end -%>> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> -
- +
+ - +
<% else -%> -
+
<% if attribute.field_type == :text_area -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%> - + <% else -%> - + <% end -%>
<% end -%> <% end -%> - @@ -66,9 +66,9 @@
<% end -%> -
-
- +
+
+
ID diff --git a/lib/generators/draft/resource/templates/views/new_form.html.erb b/lib/generators/draft/resource/templates/views/new_form.html.erb index 1d81d37d..02563aaa 100644 --- a/lib/generators/draft/resource/templates/views/new_form.html.erb +++ b/lib/generators/draft/resource/templates/views/new_form.html.erb @@ -18,21 +18,21 @@ <% end -%> <% if attribute.field_type == :check_box -%> -
+
<% if with_sentinels? -%> <% end -%> - + <% if with_sentinels? -%> <% end -%> -
<% else -%> -
+
@@ -41,7 +41,7 @@ <% if with_sentinels? -%> <% end -%> - + <% if with_sentinels? -%> <% end -%> @@ -49,7 +49,7 @@ <% if with_sentinels? -%> <% end -%> - + <% if with_sentinels? -%> <% end -%> @@ -61,7 +61,7 @@ <% end -%> <% end -%> - diff --git a/lib/generators/draft/resource/templates/views/new_form_with_errors.html.erb b/lib/generators/draft/resource/templates/views/new_form_with_errors.html.erb index cb6232b6..330a7755 100644 --- a/lib/generators/draft/resource/templates/views/new_form_with_errors.html.erb +++ b/lib/generators/draft/resource/templates/views/new_form_with_errors.html.erb @@ -3,7 +3,7 @@ <%% if @<%= singular_table_name %>.present? %> <%% if @<%= singular_table_name %>.errors.any? %> <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %> -
+
<%%= message %>
<%% end %> @@ -31,21 +31,21 @@ <% end -%> <% if attribute.field_type == :check_box -%> -
+
<% if with_sentinels? -%> <% end -%> - <%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%>> + <%%= "checked" if @<%= singular_table_name %>.<%= attribute.column_name %> %><% end -%>> <% if with_sentinels? -%> <% end -%> -
<% else -%> -
+
@@ -54,7 +54,7 @@ <% if with_sentinels? -%> <% end -%> - + <% if with_sentinels? -%> <% end -%> @@ -62,7 +62,7 @@ <% if with_sentinels? -%> <% end -%> - value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>> + value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>> <% if with_sentinels? -%> <% end -%> @@ -74,7 +74,7 @@ <% end -%> <% end -%> - diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 7496c6df..b1c8aac7 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -1,12 +1,12 @@ -
-
+
+

<%= singular_table_name.humanize %> #<%%= @the_<%= singular_table_name %>.id %> details

-
-
- +
+ @@ -15,8 +15,8 @@ <% if with_sentinels? -%> <% end -%> -
- + @@ -79,8 +79,8 @@ <% end -%> -
-
+
+

Edit <%= singular_table_name.humanize.downcase %>

@@ -88,38 +88,39 @@
method="post" <% end -%>> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%> -
- .<%= attribute.column_name %> %>> +
+ .<%= attribute.column_name %> %>> - +
<% else -%> -
+
<% if attribute.field_type == :text_area -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> + value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"> <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%> - + <% else -%> - + <% end -%>
<% end -%> <% end -%> - From d4c7453061b26e3a6f7bb9ca5e18ffea9e4207e6 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Mon, 17 Aug 2020 15:04:12 -0500 Subject: [PATCH 43/47] Fix missing 'the's in generated show page --- .../draft/resource/templates/views/show.html.erb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index b1c8aac7..1bddf31b 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -16,7 +16,7 @@ <% end -%> @@ -89,7 +89,7 @@ <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%>
- .<%= attribute.column_name %> %>> + .<%= attribute.column_name %> %>> <% if attribute.field_type == :text_area -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :datetime -%> + value="<%%= @the_<%= singular_table_name %>.<%= attribute.column_name %> %>"> <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :date -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :time -%> - + <% elsif attribute.field_type.to_s.gsub(/_.*/, "").to_sym == :integer -%> - + <% else -%> - + <% end -%>
From b749884a069c7f06472da628f604c246655d6495 Mon Sep 17 00:00:00 2001 From: Patrick McKernin Date: Wed, 19 Aug 2020 17:23:00 -0500 Subject: [PATCH 44/47] Added erros.full_messages to account notices --- .../templates/controllers/authentication_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/account/templates/controllers/authentication_controller.rb b/lib/generators/draft/account/templates/controllers/authentication_controller.rb index 4783f620..b91141e3 100644 --- a/lib/generators/draft/account/templates/controllers/authentication_controller.rb +++ b/lib/generators/draft/account/templates/controllers/authentication_controller.rb @@ -56,7 +56,7 @@ def create redirect_to("/", { :notice => "<%= singular_table_name.humanize %> account created successfully."}) else - redirect_to("/<%= singular_table_name.underscore %>_sign_up", { :alert => "<%= singular_table_name.humanize %> account failed to create successfully."}) + redirect_to("/<%= singular_table_name.underscore %>_sign_up", { :alert => @<%= singular_table_name%>.errors.full_messages.to_sentence }) end end @@ -82,7 +82,7 @@ def update redirect_to("/", { :notice => "<%= singular_table_name.humanize %> account updated successfully."}) else - render({ :template => "<%= singular_table_name.underscore %>_authentication/edit_profile_with_errors.html.erb" }) + render({ :template => "<%= singular_table_name.underscore %>_authentication/edit_profile_with_errors.html.erb" , :alert => @<%= singular_table_name%>.errors.full_messages.to_sentence }) end end From 277f732fc9570a8b2081c5fb84c301ad4197f5e9 Mon Sep 17 00:00:00 2001 From: Pat McKernin Date: Thu, 3 Dec 2020 09:34:11 -0600 Subject: [PATCH 45/47] removed div's from update and show --- .../resource/templates/views/index.html.erb | 21 +++++----------- .../resource/templates/views/show.html.erb | 24 +++++++------------ 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index b153d823..7688ebc5 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -1,15 +1,10 @@ -
-
-

- List of all <%= plural_table_name.humanize.downcase %> -

-
-
+

+ List of all <%= plural_table_name.humanize.downcase %> +

+
-
-

Add a new <%= singular_table_name.humanize.downcase %>

@@ -50,8 +45,7 @@ Create <%= singular_table_name.humanize.downcase %> -
-
+
<% if with_sentinels? -%> @@ -66,8 +60,7 @@
<% end -%> -
-
+ <%% end %>
@@ -142,7 +135,5 @@
-
-

diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index 1bddf31b..2ba15abe 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -1,10 +1,9 @@ -
-
-

- <%= singular_table_name.humanize %> #<%%= @the_<%= singular_table_name %>.id %> details -

-
+

+ <%= singular_table_name.humanize %> #<%%= @the_<%= singular_table_name %>.id %> details +

+ +
<% attributes.each do |attribute| -%> @@ -68,8 +66,6 @@ <% end -%>
-
-

@@ -79,11 +75,9 @@ <% end -%> -
-
-

- Edit <%= singular_table_name.humanize.downcase %> -

+

+ Edit <%= singular_table_name.humanize.downcase %> +

method="post" <% end -%>> <% attributes.each do |attribute| -%> @@ -124,7 +118,5 @@ Update <%= singular_table_name.humanize.downcase %>
-
-

From 16a7f52b8439582e4c3e8efd0e3ab58a073d7447 Mon Sep 17 00:00:00 2001 From: Pat McKernin Date: Thu, 3 Dec 2020 09:45:38 -0600 Subject: [PATCH 46/47] edited force_sign_in comments --- lib/generators/draft/account/account_generator.rb | 3 ++- .../account/templates/controllers/authentication_controller.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/account/account_generator.rb b/lib/generators/draft/account/account_generator.rb index 45fda601..9c84e2f7 100644 --- a/lib/generators/draft/account/account_generator.rb +++ b/lib/generators/draft/account/account_generator.rb @@ -91,7 +91,8 @@ def authentication_helpers before_action(:load_current_#{singular_table_name.underscore}) - # Uncomment this if you want to force #{plural_table_name} to sign in before any other actions + # Uncomment the "before_action" if you want to force #{plural_table_name} to sign in before any other actions + # Remember to also uncomment the "skip_before_action" in the corresponding account controller # before_action(:force_#{singular_table_name.underscore}_sign_in) def load_current_#{singular_table_name.underscore} diff --git a/lib/generators/draft/account/templates/controllers/authentication_controller.rb b/lib/generators/draft/account/templates/controllers/authentication_controller.rb index b91141e3..f888a770 100644 --- a/lib/generators/draft/account/templates/controllers/authentication_controller.rb +++ b/lib/generators/draft/account/templates/controllers/authentication_controller.rb @@ -1,7 +1,8 @@ class <%= class_name.singularize %>AuthenticationController < ApplicationController # Uncomment this if you want to force <%= plural_table_name %> to sign in before any other actions # skip_before_action(:force_<%= singular_table_name.underscore %>_sign_in, { :only => [:sign_up_form, :create, :sign_in_form, :create_cookie] }) - + # Remember to also uncomment the "before_action" in the ApplicationController + def sign_in_form render({ :template => "<%= singular_table_name.underscore %>_authentication/sign_in.html.erb" }) end From 25c38bbcfc2d31fe0165dcd49e9caf2dd2be0b02 Mon Sep 17 00:00:00 2001 From: Pat McKernin Date: Thu, 3 Dec 2020 09:54:51 -0600 Subject: [PATCH 47/47] wording --- lib/generators/draft/account/account_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/account/account_generator.rb b/lib/generators/draft/account/account_generator.rb index 9c84e2f7..539515f3 100644 --- a/lib/generators/draft/account/account_generator.rb +++ b/lib/generators/draft/account/account_generator.rb @@ -92,7 +92,7 @@ def authentication_helpers before_action(:load_current_#{singular_table_name.underscore}) # Uncomment the "before_action" if you want to force #{plural_table_name} to sign in before any other actions - # Remember to also uncomment the "skip_before_action" in the corresponding account controller + # Remember to also uncomment the "skip_before_action" in the corresponding authentication controller # before_action(:force_#{singular_table_name.underscore}_sign_in) def load_current_#{singular_table_name.underscore}