From eebc1c77c2fcb2d343f9c85742a184df7d4a6f49 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Sat, 20 May 2017 08:33:24 -0500 Subject: [PATCH 01/16] Disambiguating by breaking more conventions - Removing all instance variables to decouple variable name choices between actions that re-use templates, and to remove the additional cognitive load of learning what an instance variable is. Also, avoiding state is better practice anyway, IMO. - Using strings as keys to the `params` hash following the heuristic: "If we could change it to 'zebra' on a whim, then use a string; otherwise use a symbol." - Making variable and input names longer and more pedantic. --- .../draft/resource/resource_generator.rb | 10 +-- .../templates/controllers/controller.rb | 81 +++++++++++-------- .../controllers/read_only_controller.rb | 12 ++- .../templates/views/create_row.html.erb | 6 +- .../templates/views/destroy_row.html.erb | 6 +- .../templates/views/edit_form.html.erb | 14 ++-- .../resource/templates/views/index.html.erb | 12 +-- .../templates/views/new_form.html.erb | 10 +-- .../resource/templates/views/show.html.erb | 12 +-- .../templates/views/update_row.html.erb | 4 +- 10 files changed, 95 insertions(+), 72 deletions(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 3580fb04..0c901456 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -14,9 +14,9 @@ def generate_controller return if skip_controller? if read_only? - template "controllers/read_only_controller.rb", "app/controllers/#{plural_table_name.underscore}_controller.rb" + template "controllers/read_only_controller.rb", "app/controllers/#{plural_table_name}_controller.rb" else - template "controllers/controller.rb", "app/controllers/#{plural_table_name.underscore}_controller.rb" + template "controllers/controller.rb", "app/controllers/#{plural_table_name}_controller.rb" end end @@ -35,7 +35,7 @@ def generate_model def generate_view_files available_views.each do |view| filename = view_filename_with_extensions(view) - template filename, File.join("app/views", "#{plural_table_name}_templates", File.basename(filename)) + template filename, File.join("app/views", "#{singular_table_name}_templates", File.basename(filename)) end end @@ -52,8 +52,8 @@ def generate_routes def generate_specs return if read_only? || skip_controller? || skip_model? - template "specs/crud_spec.rb", "spec/features/crud_#{plural_table_name.underscore}_spec.rb" - template "specs/factories.rb", "spec/factories/#{plural_table_name.underscore}.rb" + template "specs/crud_spec.rb", "spec/features/crud_#{plural_table_name}_spec.rb" + template "specs/factories.rb", "spec/factories/#{plural_table_name}.rb" end private diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 4461bbe8..4d9f9b40 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -1,97 +1,112 @@ class <%= plural_table_name.camelize %>Controller < ApplicationController def index - @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all + all_<%= plural_table_name %> = <%= class_name.singularize %>.all.order(:created_at => :desc) - render("<%= plural_table_name.underscore %>_templates/index.html.erb") + render("<%= singular_table_name %>_templates/index.html.erb", :locals => { + :list_of_<%= plural_table_name %> => all_<%= plural_table_name %> + }) end def show - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_display]) + <%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(params["id_to_display"]) - render("<%= plural_table_name.underscore %>_templates/show.html.erb") + render("<%= singular_table_name %>_templates/show.html.erb", :locals => { + :the_<%= singular_table_name %> => <%= singular_table_name %>_to_show + }) end def new_form <% unless skip_validation_alerts? -%> - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new + dummy_<%= singular_table_name %> = <%= class_name.singularize %>.new + <% end -%> - render("<%= plural_table_name.underscore %>_templates/new_form.html.erb") + render("<%= singular_table_name %>_templates/new_form.html.erb", :locals => { + :<%= singular_table_name %>_with_errors => dummy_<%= singular_table_name %> + }) end def create_row - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.new + <%= singular_table_name %>_to_add = <%= class_name.singularize %>.new <% attributes.each do |attribute| -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>] + <%= singular_table_name %>_to_add.<%= attribute.column_name %> = params["<%= attribute.column_name %>_from_form"] <% end -%> <% unless skip_validation_alerts? -%> - save_status = @<%= singular_table_name.underscore %>.save + save_status = <%= singular_table_name %>_to_add.save if save_status == true - redirect_to("/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> created successfully.") + redirect_to("/<%= plural_table_name %>", :notice => "<%= singular_table_name.humanize %> created successfully.") else - render("<%= plural_table_name.underscore %>_templates/new_form.html.erb") + render("<%= singular_table_name %>_templates/new_form.html.erb", :locals => { + :<%= singular_table_name %>_with_errors => <%= singular_table_name %>_to_add + }) end <% else -%> - @<%= singular_table_name.underscore %>.save + <%= singular_table_name %>_to_add.save <% unless skip_redirect? -%> - redirect_to("/<%= @plural_table_name.underscore %>") + redirect_to("/<%= plural_table_name %>") <% else -%> - @current_count = <%= class_name.singularize %>.count - - render("<%= plural_table_name.underscore %>_templates/create_row.html.erb") + render("<%= singular_table_name %>_templates/create_row.html.erb", :locals => { + :current_count => <%= class_name.singularize %>.count + }) <% end -%> <% end -%> end def edit_form - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:prefill_with_id]) + existing_<%= singular_table_name %> = <%= class_name.singularize %>.find(params["prefill_with_id"]) - render("<%= plural_table_name.underscore %>_templates/edit_form.html.erb") + render("<%= singular_table_name %>_templates/edit_form.html.erb", :locals => { + :<%= singular_table_name %>_to_prefill => existing_<%= singular_table_name %> + }) end def update_row - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_modify]) + <%= singular_table_name %>_to_change = <%= class_name.singularize %>.find(params["id_to_modify"]) <% attributes.each do |attribute| -%> - @<%= singular_table_name.underscore %>.<%= attribute.column_name %> = params[:<%= attribute.column_name %>] + <%= singular_table_name %>_to_change.<%= attribute.column_name %> = params["<%= attribute.column_name %>_from_form"] <% end -%> <% unless skip_validation_alerts? -%> - save_status = @<%= singular_table_name.underscore %>.save + save_status = <%= singular_table_name %>_to_change.save if save_status == true - redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.") + redirect_to("/<%= plural_table_name %>/#{<%= singular_table_name %>_to_change.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.") else - render("<%= plural_table_name.underscore %>_templates/edit_form.html.erb") + render("<%= singular_table_name %>_templates/edit_form.html.erb", :locals => { + :<%= singular_table_name %>_to_prefill => <%= singular_table_name %>_to_change + }) end <% else -%> - @<%= singular_table_name.underscore %>.save + <%= singular_table_name %>_to_change.save <% unless skip_redirect? -%> - redirect_to("/<%= @plural_table_name.underscore %>/#{@<%= singular_table_name.underscore %>.id}") + redirect_to("/<%= plural_table_name %>/#{<%= singular_table_name %>_to_change.id}") <% else -%> - render("<%= plural_table_name.underscore %>_templates/update_row.html.erb") + render("<%= singular_table_name %>_templates/update_row.html.erb", :locals => { + :<%= singular_table_name %>_to_prefill => <%= singular_table_name %>_to_change + }) <% end -%> <% end -%> end def destroy_row - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id_to_remove]) + <%= singular_table_name %>_to_delete = <%= class_name.singularize %>.find(params["id_to_remove"]) - @<%= singular_table_name.underscore %>.destroy + <%= singular_table_name %>_to_delete.destroy <% unless skip_validation_alerts? -%> - redirect_to("/<%= @plural_table_name.underscore %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.") + redirect_to("/<%= plural_table_name %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.") <% else -%> <% unless skip_redirect? -%> - redirect_to("/<%= @plural_table_name.underscore %>") + redirect_to("/<%= plural_table_name %>") <% else -%> - @remaining_count = <%= class_name.singularize %>.count - - render("<%= plural_table_name.underscore %>_templates/destroy_row.html.erb") + render("<%= singular_table_name %>_templates/destroy_row.html.erb", :locals => { + :remaining_count => <%= class_name.singularize %>.count + }) <% end -%> <% end -%> end diff --git a/lib/generators/draft/resource/templates/controllers/read_only_controller.rb b/lib/generators/draft/resource/templates/controllers/read_only_controller.rb index a6a13d1f..a3895496 100644 --- a/lib/generators/draft/resource/templates/controllers/read_only_controller.rb +++ b/lib/generators/draft/resource/templates/controllers/read_only_controller.rb @@ -1,9 +1,17 @@ class <%= plural_table_name.camelize %>Controller < ApplicationController def index - @<%= plural_table_name.underscore %> = <%= class_name.singularize %>.all + all_<%= plural_table_name %> = <%= class_name.singularize %>.all.order(:created_at => :desc) + + render("<%= plural_table_name %>_templates/index.html.erb", :locals => { + :list_of_<%= plural_table_name %> => all_<%= plural_table_name %> + }) end def show - @<%= singular_table_name.underscore %> = <%= class_name.singularize %>.find(params[:id]) + <%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(params[:id_to_display]) + + render("<%= plural_table_name %>_templates/show.html.erb", :locals => { + :the_<%= singular_table_name %> => <%= singular_table_name %>_to_show + }) end end diff --git a/lib/generators/draft/resource/templates/views/create_row.html.erb b/lib/generators/draft/resource/templates/views/create_row.html.erb index c3fe0906..28a2b959 100644 --- a/lib/generators/draft/resource/templates/views/create_row.html.erb +++ b/lib/generators/draft/resource/templates/views/create_row.html.erb @@ -1,11 +1,11 @@ -

You created <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>!

+

You created a <%= singular_table_name.humanize.downcase %>!

- There are now <%%= @current_count %> <%= plural_table_name.humanize.downcase %>. + There are now <%%= current_count %> <%= plural_table_name.humanize.downcase %>.

- + Click here diff --git a/lib/generators/draft/resource/templates/views/destroy_row.html.erb b/lib/generators/draft/resource/templates/views/destroy_row.html.erb index 60a796ea..81afdc25 100644 --- a/lib/generators/draft/resource/templates/views/destroy_row.html.erb +++ b/lib/generators/draft/resource/templates/views/destroy_row.html.erb @@ -1,11 +1,11 @@ -

You deleted <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>!

+

You deleted a <%= singular_table_name.humanize.downcase %>!

- There are now <%%= @remaining_count %> <%= plural_table_name.humanize.downcase %>. + There are now <%%= remaining_count %> <%= plural_table_name.humanize.downcase %>.

- + Click here 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 5bf5d288..a60fe703 100644 --- a/lib/generators/draft/resource/templates/views/edit_form.html.erb +++ b/lib/generators/draft/resource/templates/views/edit_form.html.erb @@ -1,7 +1,7 @@ <% unless skip_validation_alerts? -%> -<%% if @<%= singular_table_name %>.errors.any? %> - <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %> +<%% if <%= singular_table_name %>_to_prefill.errors.any? %> + <%% <%= singular_table_name %>_to_prefill.errors.full_messages.each do |message| %>

@@ -12,18 +12,18 @@ <% end -%>

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


-
method="post"<% end -%>> + method="post"<% end -%>> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%>
@@ -34,9 +34,9 @@ <% if attribute.field_type == :text_area -%> - + <% else -%> - + <% 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 2caca9d1..45b558f8 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -32,28 +32,28 @@ - <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %> + <%% list_of_<%= plural_table_name %>.each do |the_current_<%= singular_table_name %>| %> - <%%= <%= singular_table_name %>.id %> + <%%= the_current_<%= singular_table_name %>.id %> <% attributes.each do |attribute| -%> - <%%= <%= singular_table_name %>.<%= attribute.column_name %> %> + <%%= the_current_<%= singular_table_name %>.<%= attribute.column_name %> %> <% end -%> - <%%= time_ago_in_words(<%= singular_table_name %>.created_at) %> ago + <%%= time_ago_in_words(the_current_<%= singular_table_name %>.created_at) %> ago - <%%= time_ago_in_words(<%= singular_table_name %>.updated_at) %> ago + <%%= time_ago_in_words(the_current_<%= singular_table_name %>.updated_at) %> ago - + Show details 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 130f78fb..ad1b60b9 100644 --- a/lib/generators/draft/resource/templates/views/new_form.html.erb +++ b/lib/generators/draft/resource/templates/views/new_form.html.erb @@ -1,7 +1,7 @@ <% unless skip_validation_alerts? -%> -<%% if @<%= singular_table_name %>.errors.any? %> - <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %> +<%% if <%= singular_table_name %>_with_errors.errors.any? %> + <%% <%= singular_table_name %>_with_errors.errors.full_messages.each do |message| %>
@@ -23,7 +23,7 @@ <% if attribute.field_type == :check_box -%>
@@ -34,9 +34,9 @@ <% if attribute.field_type == :text_area -%> - + <% else -%> - value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>> + value="<%%= <%= singular_table_name %>_with_errors.<%= attribute.column_name %> %>"<% 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 ad19cebf..f7541769 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -1,8 +1,8 @@

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

- + Edit <%= singular_table_name.humanize.downcase %> @@ -14,7 +14,7 @@ <%= attribute.human_name %>
- <%%= @<%= singular_table_name %>.<%= attribute.column_name %> %> + <%%= the_<%= singular_table_name %>.<%= attribute.column_name %> %>
<% end -%> @@ -22,19 +22,19 @@ Created at
- <%%= time_ago_in_words(@<%= singular_table_name %>.created_at) %> ago + <%%= time_ago_in_words(the_<%= singular_table_name %>.created_at) %> ago
Updated at
- <%%= time_ago_in_words(@<%= singular_table_name %>.updated_at) %> ago + <%%= time_ago_in_words(the_<%= singular_table_name %>.updated_at) %> ago
<% unless read_only? -%> - + Delete <%= singular_table_name.humanize.downcase %> <% end -%> diff --git a/lib/generators/draft/resource/templates/views/update_row.html.erb b/lib/generators/draft/resource/templates/views/update_row.html.erb index 42048f44..735b8a13 100644 --- a/lib/generators/draft/resource/templates/views/update_row.html.erb +++ b/lib/generators/draft/resource/templates/views/update_row.html.erb @@ -1,7 +1,7 @@ -

You updated <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>!

+

You updated <%= singular_table_name.humanize.downcase %> #<%%= <%= singular_table_name %>_to_prefill.id %>!

- + Click here From e8b006c89f7e4133c09e8751261e49e3f6a1330e Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Sat, 20 May 2017 10:05:40 -0500 Subject: [PATCH 02/16] Add new_form_with_errors --- .../draft/resource/resource_generator.rb | 2 +- .../templates/controllers/controller.rb | 10 +--- .../templates/views/new_form.html.erb | 19 ++----- .../views/new_form_with_errors.html.erb | 54 +++++++++++++++++++ 4 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 lib/generators/draft/resource/templates/views/new_form_with_errors.html.erb diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 0c901456..902d9f8d 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -148,7 +148,7 @@ def available_views elsif skip_redirect? %w(index show new_form create_row edit_form update_row destroy_row) else - %w(index new_form edit_form show) + %w(index new_form new_form_with_errors edit_form show) end end diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 4d9f9b40..5bdd69b6 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -16,13 +16,7 @@ def show end def new_form -<% unless skip_validation_alerts? -%> - dummy_<%= singular_table_name %> = <%= class_name.singularize %>.new - -<% end -%> - render("<%= singular_table_name %>_templates/new_form.html.erb", :locals => { - :<%= singular_table_name %>_with_errors => dummy_<%= singular_table_name %> - }) + render("<%= singular_table_name %>_templates/new_form.html.erb") end def create_row @@ -38,7 +32,7 @@ def create_row if save_status == true redirect_to("/<%= plural_table_name %>", :notice => "<%= singular_table_name.humanize %> created successfully.") else - render("<%= singular_table_name %>_templates/new_form.html.erb", :locals => { + render("<%= singular_table_name %>_templates/new_form_with_errors.html.erb", :locals => { :<%= singular_table_name %>_with_errors => <%= singular_table_name %>_to_add }) end 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 ad1b60b9..8dc9ac67 100644 --- a/lib/generators/draft/resource/templates/views/new_form.html.erb +++ b/lib/generators/draft/resource/templates/views/new_form.html.erb @@ -1,16 +1,3 @@ -<% unless skip_validation_alerts? -%> - -<%% if <%= singular_table_name %>_with_errors.errors.any? %> - <%% <%= singular_table_name %>_with_errors.errors.full_messages.each do |message| %> -

- - - <%%= message %> -
- <%% end %> -<%% end %> - -<% end -%>

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

@@ -23,7 +10,7 @@ <% if attribute.field_type == :check_box -%>
@@ -34,9 +21,9 @@ <% if attribute.field_type == :text_area -%> - + <% else -%> - value="<%%= <%= singular_table_name %>_with_errors.<%= attribute.column_name %> %>"<% end -%>> + <% 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 new file mode 100644 index 00000000..ad1b60b9 --- /dev/null +++ b/lib/generators/draft/resource/templates/views/new_form_with_errors.html.erb @@ -0,0 +1,54 @@ +<% unless skip_validation_alerts? -%> + +<%% if <%= singular_table_name %>_with_errors.errors.any? %> + <%% <%= singular_table_name %>_with_errors.errors.full_messages.each do |message| %> +
+ + + <%%= message %> +
+ <%% end %> +<%% end %> + +<% end -%> +

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

+ +
+ + method="post"<% end -%>> +<% attributes.each do |attribute| -%> + +<% if attribute.field_type == :check_box -%> +
+ +
+<% else -%> +
+ + +<% if attribute.field_type == :text_area -%> + +<% else -%> + value="<%%= <%= singular_table_name %>_with_errors.<%= attribute.column_name %> %>"<% end -%>> +<% end -%> +
+<% end -%> + +<% end -%> + + + +
+ + + Go back + From 210d1c3e0a57864b0f893a61806b63e03bdb5934 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Sat, 20 May 2017 11:10:10 -0500 Subject: [PATCH 03/16] Simplify alerts --- lib/generators/draft/layout/templates/_flashes.html.erb | 4 ++-- .../draft/resource/templates/views/edit_form.html.erb | 2 +- .../resource/templates/views/new_form_with_errors.html.erb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/generators/draft/layout/templates/_flashes.html.erb b/lib/generators/draft/layout/templates/_flashes.html.erb index fa49e23b..7c8c24dc 100644 --- a/lib/generators/draft/layout/templates/_flashes.html.erb +++ b/lib/generators/draft/layout/templates/_flashes.html.erb @@ -2,14 +2,14 @@
<%% if notice.present? %>
- + <%%= notice %>
<%% end %> <%% if alert.present? %>
- + <%%= alert %>
<%% 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 a60fe703..46383e20 100644 --- a/lib/generators/draft/resource/templates/views/edit_form.html.erb +++ b/lib/generators/draft/resource/templates/views/edit_form.html.erb @@ -3,7 +3,7 @@ <%% if <%= singular_table_name %>_to_prefill.errors.any? %> <%% <%= singular_table_name %>_to_prefill.errors.full_messages.each do |message| %>
- + <%%= message %>
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 ad1b60b9..ea5daae1 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 %>_with_errors.errors.any? %> <%% <%= singular_table_name %>_with_errors.errors.full_messages.each do |message| %>
- + <%%= message %>
From 251fa4bb66ffa000fa2d5029a8b6b8273ce3d123 Mon Sep 17 00:00:00 2001 From: Raghu Betina Date: Sat, 20 May 2017 11:15:01 -0500 Subject: [PATCH 04/16] Put back rails info link --- lib/generators/draft/layout/templates/_navbar.html.erb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/generators/draft/layout/templates/_navbar.html.erb b/lib/generators/draft/layout/templates/_navbar.html.erb index ef09adc3..82d3cc20 100644 --- a/lib/generators/draft/layout/templates/_navbar.html.erb +++ b/lib/generators/draft/layout/templates/_navbar.html.erb @@ -24,6 +24,11 @@ <% end -%> +
  • + + All Routes + +
  • <% if devise_routes.any? -%> <% devise_routes.each do |devise_route| -%> From 3d9b939bd095afac7e6d2679ce3161b6471ea703 Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 20:41:48 -0600 Subject: [PATCH 05/16] Alerts in containers --- .../draft/layout/templates/_flashes.html.erb | 36 ++++++++++++------- .../draft/layout/templates/layout.html.erb | 4 +-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/generators/draft/layout/templates/_flashes.html.erb b/lib/generators/draft/layout/templates/_flashes.html.erb index 7c8c24dc..929d25f2 100644 --- a/lib/generators/draft/layout/templates/_flashes.html.erb +++ b/lib/generators/draft/layout/templates/_flashes.html.erb @@ -1,17 +1,27 @@ -
    -
    - <%% if notice.present? %> -
    - - <%%= notice %> +<%% if notice.present? %> +
    +
    +
    +
    + + + <%%= notice %> +
    - <%% end %> +
    +
    +<%% end %> + +<%% if alert.present? %> +
    +
    +
    +
    + - <%% if alert.present? %> -
    - - <%%= alert %> + <%%= alert %> +
    - <%% end %> +
    -
    +<%% end %> diff --git a/lib/generators/draft/layout/templates/layout.html.erb b/lib/generators/draft/layout/templates/layout.html.erb index 346cebe4..c3df8692 100644 --- a/lib/generators/draft/layout/templates/layout.html.erb +++ b/lib/generators/draft/layout/templates/layout.html.erb @@ -20,9 +20,9 @@ <%%= render "shared/navbar" %> -
    - <%%= render "shared/flashes" %> + <%%= render "shared/flashes" %> +
    <%%= yield %>
    From ee12f24d90a6499360ddb9614125fa7ab0d97494 Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 20:45:02 -0600 Subject: [PATCH 06/16] Remove rails info link --- lib/generators/draft/layout/templates/_navbar.html.erb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/generators/draft/layout/templates/_navbar.html.erb b/lib/generators/draft/layout/templates/_navbar.html.erb index 82d3cc20..ef09adc3 100644 --- a/lib/generators/draft/layout/templates/_navbar.html.erb +++ b/lib/generators/draft/layout/templates/_navbar.html.erb @@ -24,11 +24,6 @@ <% end -%> -
  • - - All Routes - -
  • <% if devise_routes.any? -%> <% devise_routes.each do |devise_route| -%> From 05abf80f4859639ac49bad51466bb3ab7e1fc07a Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 20:46:08 -0600 Subject: [PATCH 07/16] Better copy on Devise edit registration link --- lib/generators/draft/layout/templates/_navbar.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/layout/templates/_navbar.html.erb b/lib/generators/draft/layout/templates/_navbar.html.erb index ef09adc3..9ccc0940 100644 --- a/lib/generators/draft/layout/templates/_navbar.html.erb +++ b/lib/generators/draft/layout/templates/_navbar.html.erb @@ -43,7 +43,7 @@ <%% else %>
  • - Edit profile + Edit <%= devise_route[1].humanize %>
  • From 01dcecb06f1edc13d136dbb5b3fe4ed6c3ae7d39 Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 20:48:34 -0600 Subject: [PATCH 08/16] Re-ivar index --- .../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 5bdd69b6..637aec21 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -1,10 +1,8 @@ class <%= plural_table_name.camelize %>Controller < ApplicationController def index - all_<%= plural_table_name %> = <%= class_name.singularize %>.all.order(:created_at => :desc) + @list_of_<%= plural_table_name %> = <%= class_name.singularize %>.all.order({ :created_at => :desc }) - render("<%= singular_table_name %>_templates/index.html.erb", :locals => { - :list_of_<%= plural_table_name %> => all_<%= plural_table_name %> - }) + render("<%= singular_table_name %>_templates/index.html.erb") end def show diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index 45b558f8..aa124116 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -32,7 +32,7 @@ - <%% list_of_<%= plural_table_name %>.each do |the_current_<%= singular_table_name %>| %> + <%% @list_of_<%= plural_table_name %>.each do |the_current_<%= singular_table_name %>| %> <%%= the_current_<%= singular_table_name %>.id %> From 9a205e3a711584453f15e10f8d1ec6e5f624d7b7 Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 20:54:14 -0600 Subject: [PATCH 09/16] De-ivar show --- .../draft/resource/templates/controllers/controller.rb | 8 ++++---- .../draft/resource/templates/views/show.html.erb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 637aec21..84ec7a89 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -6,11 +6,11 @@ def index end def show - <%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(params["id_to_display"]) + id_of_<%= singular_table_name %>_to_show = params.fetch("id_to_display") + + @<%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_show) - render("<%= singular_table_name %>_templates/show.html.erb", :locals => { - :the_<%= singular_table_name %> => <%= singular_table_name %>_to_show - }) + render("<%= singular_table_name %>_templates/show.html.erb") end def new_form diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index f7541769..c58f1185 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -14,7 +14,7 @@ <%= attribute.human_name %>
    - <%%= the_<%= singular_table_name %>.<%= attribute.column_name %> %> + <%%= @the_<%= singular_table_name %>.<%= attribute.column_name %> %>
    <% end -%> @@ -22,19 +22,19 @@ Created at
    - <%%= time_ago_in_words(the_<%= singular_table_name %>.created_at) %> ago + <%%= time_ago_in_words(@the_<%= singular_table_name %>.created_at) %> ago
    Updated at
    - <%%= time_ago_in_words(the_<%= singular_table_name %>.updated_at) %> ago + <%%= time_ago_in_words(@the_<%= singular_table_name %>.updated_at) %> ago
    <% unless read_only? -%> - + Delete <%= singular_table_name.humanize.downcase %> <% end -%> From 5fb7865ed82a3231595a381ac9ad7737b52effae Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 21:06:13 -0600 Subject: [PATCH 10/16] De-ivar new/create --- .../templates/controllers/controller.rb | 20 +++++++++---------- .../templates/views/create_row.html.erb | 2 +- .../resource/templates/views/index.html.erb | 16 --------------- .../views/new_form_with_errors.html.erb | 10 +++++----- 4 files changed, 15 insertions(+), 33 deletions(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index 84ec7a89..a8b2989e 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 id_of_<%= singular_table_name %>_to_show = params.fetch("id_to_display") - + @<%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_show) render("<%= singular_table_name %>_templates/show.html.erb") @@ -18,31 +18,29 @@ def new_form end def create_row - <%= singular_table_name %>_to_add = <%= class_name.singularize %>.new + @<%= singular_table_name %>_to_add = <%= class_name.singularize %>.new <% attributes.each do |attribute| -%> - <%= singular_table_name %>_to_add.<%= attribute.column_name %> = params["<%= attribute.column_name %>_from_form"] + @<%= singular_table_name %>_to_add.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_form") <% end -%> <% unless skip_validation_alerts? -%> - save_status = <%= singular_table_name %>_to_add.save + save_status = @<%= singular_table_name %>_to_add.save if save_status == true redirect_to("/<%= plural_table_name %>", :notice => "<%= singular_table_name.humanize %> created successfully.") else - render("<%= singular_table_name %>_templates/new_form_with_errors.html.erb", :locals => { - :<%= singular_table_name %>_with_errors => <%= singular_table_name %>_to_add - }) + render("<%= singular_table_name %>_templates/new_form_with_errors.html.erb") end <% else -%> - <%= singular_table_name %>_to_add.save + @<%= singular_table_name %>_to_add.save <% unless skip_redirect? -%> redirect_to("/<%= plural_table_name %>") <% else -%> - render("<%= singular_table_name %>_templates/create_row.html.erb", :locals => { - :current_count => <%= class_name.singularize %>.count - }) + @current_<%= singular_table_name %>_count = <%= class_name.singularize %>.count + + render("<%= singular_table_name %>_templates/create_row.html.erb") <% end -%> <% end -%> end diff --git a/lib/generators/draft/resource/templates/views/create_row.html.erb b/lib/generators/draft/resource/templates/views/create_row.html.erb index 28a2b959..00b79431 100644 --- a/lib/generators/draft/resource/templates/views/create_row.html.erb +++ b/lib/generators/draft/resource/templates/views/create_row.html.erb @@ -1,7 +1,7 @@

    You created a <%= singular_table_name.humanize.downcase %>!

    - There are now <%%= current_count %> <%= plural_table_name.humanize.downcase %>. + There are now <%%= @current_<%= singular_table_name %>_count %> <%= plural_table_name.humanize.downcase %>.

    diff --git a/lib/generators/draft/resource/templates/views/index.html.erb b/lib/generators/draft/resource/templates/views/index.html.erb index aa124116..3b9c8007 100644 --- a/lib/generators/draft/resource/templates/views/index.html.erb +++ b/lib/generators/draft/resource/templates/views/index.html.erb @@ -20,14 +20,6 @@ <% end -%> - - Created at - - - - Updated at - - @@ -44,14 +36,6 @@ <% end -%> - - <%%= time_ago_in_words(the_current_<%= singular_table_name %>.created_at) %> ago - - - - <%%= time_ago_in_words(the_current_<%= singular_table_name %>.updated_at) %> ago - - Show details 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 ea5daae1..0fc925ac 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 @@ -1,7 +1,7 @@ <% unless skip_validation_alerts? -%> -<%% if <%= singular_table_name %>_with_errors.errors.any? %> - <%% <%= singular_table_name %>_with_errors.errors.full_messages.each do |message| %> +<%% if @<%= singular_table_name %>_to_add.errors.any? %> + <%% @<%= singular_table_name %>_to_add.errors.full_messages.each do |message| %>

    <% end -%> From ecd241ab0b03b5bdc9f8c3a75d5df8a2c69841c1 Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 21:33:13 -0600 Subject: [PATCH 11/16] Prepare new and edit for partializing --- .../draft/resource/resource_generator.rb | 2 +- .../templates/controllers/controller.rb | 18 +++---- .../templates/views/edit_form.html.erb | 23 ++------ .../views/edit_form_with_errors.html.erb | 54 +++++++++++++++++++ .../views/new_form_with_errors.html.erb | 10 ++-- 5 files changed, 74 insertions(+), 33 deletions(-) create mode 100644 lib/generators/draft/resource/templates/views/edit_form_with_errors.html.erb diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 902d9f8d..48a0b12a 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -148,7 +148,7 @@ def available_views elsif skip_redirect? %w(index show new_form create_row edit_form update_row destroy_row) else - %w(index new_form new_form_with_errors edit_form show) + %w(index show new_form new_form_with_errors edit_form edit_form_with_errors) end end diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index a8b2989e..b704a25b 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -18,14 +18,14 @@ def new_form end def create_row - @<%= singular_table_name %>_to_add = <%= class_name.singularize %>.new + @<%= singular_table_name %> = <%= class_name.singularize %>.new <% attributes.each do |attribute| -%> - @<%= singular_table_name %>_to_add.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_form") + @<%= singular_table_name %>.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_form") <% end -%> <% unless skip_validation_alerts? -%> - save_status = @<%= singular_table_name %>_to_add.save + save_status = @<%= singular_table_name %>.save if save_status == true redirect_to("/<%= plural_table_name %>", :notice => "<%= singular_table_name.humanize %> created successfully.") @@ -33,24 +33,24 @@ def create_row render("<%= singular_table_name %>_templates/new_form_with_errors.html.erb") end <% else -%> - @<%= singular_table_name %>_to_add.save + @<%= singular_table_name %>.save <% unless skip_redirect? -%> redirect_to("/<%= plural_table_name %>") <% else -%> @current_<%= singular_table_name %>_count = <%= class_name.singularize %>.count - + render("<%= singular_table_name %>_templates/create_row.html.erb") <% end -%> <% end -%> end def edit_form - existing_<%= singular_table_name %> = <%= class_name.singularize %>.find(params["prefill_with_id"]) + existing_id = params.fetch("id_to_edit") - render("<%= singular_table_name %>_templates/edit_form.html.erb", :locals => { - :<%= singular_table_name %>_to_prefill => existing_<%= singular_table_name %> - }) + @<%= singular_table_name %> = <%= class_name.singularize %>.find(existing_id) + + render("<%= singular_table_name %>_templates/edit_form.html.erb") end def update_row 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 46383e20..8259711e 100644 --- a/lib/generators/draft/resource/templates/views/edit_form.html.erb +++ b/lib/generators/draft/resource/templates/views/edit_form.html.erb @@ -1,29 +1,16 @@ -<% unless skip_validation_alerts? -%> - -<%% if <%= singular_table_name %>_to_prefill.errors.any? %> - <%% <%= singular_table_name %>_to_prefill.errors.full_messages.each do |message| %> -
    - - - <%%= message %> -
    - <%% end %> -<%% end %> - -<% end -%>

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


    -
    method="post"<% end -%>> + method="post"<% end -%>> <% attributes.each do |attribute| -%> <% if attribute.field_type == :check_box -%>
    @@ -34,9 +21,9 @@ <% if attribute.field_type == :text_area -%> - + <% else -%> - + <% 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 new file mode 100644 index 00000000..2fbadf57 --- /dev/null +++ b/lib/generators/draft/resource/templates/views/edit_form_with_errors.html.erb @@ -0,0 +1,54 @@ +<% unless skip_validation_alerts? -%> + +<%% if @<%= singular_table_name %>.errors.any? %> + <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %> +
    + + + <%%= message %> +
    + <%% end %> +<%% end %> + +<% end -%> +

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

    + +
    + + method="post"<% end -%>> +<% attributes.each do |attribute| -%> + +<% if attribute.field_type == :check_box -%> +
    + +
    +<% else -%> +
    + + +<% if attribute.field_type == :text_area -%> + +<% else -%> + +<% end -%> +
    +<% end -%> + +<% end -%> + + + +
    + +
    + Go back + 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 0fc925ac..3c195d88 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 @@ -1,7 +1,7 @@ <% unless skip_validation_alerts? -%> -<%% if @<%= singular_table_name %>_to_add.errors.any? %> - <%% @<%= singular_table_name %>_to_add.errors.full_messages.each do |message| %> +<%% if @<%= singular_table_name %>.errors.any? %> + <%% @<%= singular_table_name %>.errors.full_messages.each do |message| %>
    @@ -23,7 +23,7 @@ <% if attribute.field_type == :check_box -%>
    @@ -34,9 +34,9 @@ <% if attribute.field_type == :text_area -%> - + <% else -%> - value="<%%= @<%= singular_table_name %>_to_add.<%= attribute.column_name %> %>"<% end -%>> + value="<%%= @<%= singular_table_name %>.<%= attribute.column_name %> %>"<% end -%>> <% end -%>
    <% end -%> From 0515e84ce557a142bfb2d3bb1e489027c9d5679b Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 21:40:40 -0600 Subject: [PATCH 12/16] De-ivar destroy --- .../templates/controllers/controller.rb | 38 +++++++++---------- .../controllers/read_only_controller.rb | 14 +++---- .../templates/views/destroy_row.html.erb | 2 +- .../templates/views/update_row.html.erb | 4 +- 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/lib/generators/draft/resource/templates/controllers/controller.rb b/lib/generators/draft/resource/templates/controllers/controller.rb index b704a25b..c6b151b3 100644 --- a/lib/generators/draft/resource/templates/controllers/controller.rb +++ b/lib/generators/draft/resource/templates/controllers/controller.rb @@ -46,47 +46,47 @@ def create_row end def edit_form - existing_id = params.fetch("id_to_edit") + id_of_<%= singular_table_name %>_to_prefill = params.fetch("id_to_edit") - @<%= singular_table_name %> = <%= class_name.singularize %>.find(existing_id) + @<%= singular_table_name %> = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_prefill) render("<%= singular_table_name %>_templates/edit_form.html.erb") end def update_row - <%= singular_table_name %>_to_change = <%= class_name.singularize %>.find(params["id_to_modify"]) + id_of_<%= singular_table_name %>_to_change = params.fetch("id_to_modify") + + @<%= singular_table_name %>_to_change = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_change) <% attributes.each do |attribute| -%> - <%= singular_table_name %>_to_change.<%= attribute.column_name %> = params["<%= attribute.column_name %>_from_form"] + @<%= singular_table_name %>_to_change.<%= attribute.column_name %> = params.fetch("<%= attribute.column_name %>_from_form") <% end -%> <% unless skip_validation_alerts? -%> - save_status = <%= singular_table_name %>_to_change.save + save_status = @<%= singular_table_name %>_to_change.save if save_status == true - redirect_to("/<%= plural_table_name %>/#{<%= singular_table_name %>_to_change.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.") + redirect_to("/<%= plural_table_name %>/#{@<%= singular_table_name %>_to_change.id}", :notice => "<%= singular_table_name.humanize %> updated successfully.") else - render("<%= singular_table_name %>_templates/edit_form.html.erb", :locals => { - :<%= singular_table_name %>_to_prefill => <%= singular_table_name %>_to_change - }) + render("<%= singular_table_name %>_templates/edit_form_with_errors.html.erb") end <% else -%> - <%= singular_table_name %>_to_change.save + @<%= singular_table_name %>_to_change.save <% unless skip_redirect? -%> - redirect_to("/<%= plural_table_name %>/#{<%= singular_table_name %>_to_change.id}") + redirect_to("/<%= plural_table_name %>/#{@<%= singular_table_name %>_to_change.id}") <% else -%> - render("<%= singular_table_name %>_templates/update_row.html.erb", :locals => { - :<%= singular_table_name %>_to_prefill => <%= singular_table_name %>_to_change - }) + render("<%= singular_table_name %>_templates/update_row.html.erb") <% end -%> <% end -%> end def destroy_row - <%= singular_table_name %>_to_delete = <%= class_name.singularize %>.find(params["id_to_remove"]) + id_of_<%= singular_table_name %>_to_delete = params.fetch("id_to_remove") + + @<%= singular_table_name %>_to_toast = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_delete) - <%= singular_table_name %>_to_delete.destroy + @<%= singular_table_name %>_to_toast.destroy <% unless skip_validation_alerts? -%> redirect_to("/<%= plural_table_name %>", :notice => "<%= singular_table_name.humanize %> deleted successfully.") @@ -94,9 +94,9 @@ def destroy_row <% unless skip_redirect? -%> redirect_to("/<%= plural_table_name %>") <% else -%> - render("<%= singular_table_name %>_templates/destroy_row.html.erb", :locals => { - :remaining_count => <%= class_name.singularize %>.count - }) + @remaining_<%= singular_table_name %>_count = <%= class_name.singularize %>.count + + render("<%= singular_table_name %>_templates/destroy_row.html.erb") <% end -%> <% end -%> end diff --git a/lib/generators/draft/resource/templates/controllers/read_only_controller.rb b/lib/generators/draft/resource/templates/controllers/read_only_controller.rb index a3895496..18a2aea9 100644 --- a/lib/generators/draft/resource/templates/controllers/read_only_controller.rb +++ b/lib/generators/draft/resource/templates/controllers/read_only_controller.rb @@ -1,17 +1,15 @@ class <%= plural_table_name.camelize %>Controller < ApplicationController def index - all_<%= plural_table_name %> = <%= class_name.singularize %>.all.order(:created_at => :desc) + @list_of_<%= plural_table_name %> = <%= class_name.singularize %>.all.order({ :created_at => :desc }) - render("<%= plural_table_name %>_templates/index.html.erb", :locals => { - :list_of_<%= plural_table_name %> => all_<%= plural_table_name %> - }) + render("<%= singular_table_name %>_templates/index.html.erb") end def show - <%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(params[:id_to_display]) + id_of_<%= singular_table_name %>_to_show = params.fetch("id_to_display") - render("<%= plural_table_name %>_templates/show.html.erb", :locals => { - :the_<%= singular_table_name %> => <%= singular_table_name %>_to_show - }) + @<%= singular_table_name %>_to_show = <%= class_name.singularize %>.find(id_of_<%= singular_table_name %>_to_show) + + render("<%= singular_table_name %>_templates/show.html.erb") end end diff --git a/lib/generators/draft/resource/templates/views/destroy_row.html.erb b/lib/generators/draft/resource/templates/views/destroy_row.html.erb index 81afdc25..638046a9 100644 --- a/lib/generators/draft/resource/templates/views/destroy_row.html.erb +++ b/lib/generators/draft/resource/templates/views/destroy_row.html.erb @@ -1,7 +1,7 @@

    You deleted a <%= singular_table_name.humanize.downcase %>!

    - There are now <%%= remaining_count %> <%= plural_table_name.humanize.downcase %>. + There are now <%%= @remaining_<%= singular_table_name %>_count %> <%= plural_table_name.humanize.downcase %>.

    diff --git a/lib/generators/draft/resource/templates/views/update_row.html.erb b/lib/generators/draft/resource/templates/views/update_row.html.erb index 735b8a13..b61e6b50 100644 --- a/lib/generators/draft/resource/templates/views/update_row.html.erb +++ b/lib/generators/draft/resource/templates/views/update_row.html.erb @@ -1,7 +1,7 @@ -

    You updated <%= singular_table_name.humanize.downcase %> #<%%= <%= singular_table_name %>_to_prefill.id %>!

    +

    You updated <%= singular_table_name.humanize.downcase %> #<%%= @<%= singular_table_name %>.id %>!

    - + Click here From 2a6a10426fba321327a7d7df855ad5e3d94f4098 Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 21:45:48 -0600 Subject: [PATCH 13/16] Cleanup --- lib/generators/draft/resource/resource_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/resource/resource_generator.rb b/lib/generators/draft/resource/resource_generator.rb index 48a0b12a..71dcc2df 100644 --- a/lib/generators/draft/resource/resource_generator.rb +++ b/lib/generators/draft/resource/resource_generator.rb @@ -74,7 +74,7 @@ def golden_seven_routes get("/#{plural_table_name}/:id_to_display", { :controller => "#{plural_table_name}", :action => "show" }) # UPDATE - get("/#{plural_table_name}/:prefill_with_id/edit", { :controller => "#{plural_table_name}", :action => "edit_form" }) + get("/#{plural_table_name}/:id_to_edit/edit", { :controller => "#{plural_table_name}", :action => "edit_form" }) #{skip_post? ? "get" : "post"}("/update_#{singular_table_name}/:id_to_modify", { :controller => "#{plural_table_name}", :action => "update_row" }) # DELETE From 2b2e0caad4b500c2998082cf355539bb82717986 Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 21:56:50 -0600 Subject: [PATCH 14/16] FactoryGirl => FactoryBot --- lib/generators/draft/resource/templates/specs/factories.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/draft/resource/templates/specs/factories.rb b/lib/generators/draft/resource/templates/specs/factories.rb index e11ee8d9..3f12f07d 100644 --- a/lib/generators/draft/resource/templates/specs/factories.rb +++ b/lib/generators/draft/resource/templates/specs/factories.rb @@ -3,7 +3,7 @@ require Rails.root.join("spec", "support", "increasing_random.rb") -FactoryGirl.define do +FactoryBot.define do factory :<%= singular_table_name %> do sequence(:id, IncreasingRandom.new) { |n| n.value } <% attributes.each do |attribute| -%> From 33ffdcf0a4744d1442651aee3bd66981cef5c7f8 Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 22:04:49 -0600 Subject: [PATCH 15/16] Bug --- lib/generators/draft/resource/templates/views/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index c58f1185..f9a167b3 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -1,8 +1,8 @@

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

    - + Edit <%= singular_table_name.humanize.downcase %> From a885da0d3e52b98159b2d2afee5242a87afea42e Mon Sep 17 00:00:00 2001 From: demo-student-123 Date: Tue, 7 Nov 2017 22:08:53 -0600 Subject: [PATCH 16/16] bug --- .../draft/resource/templates/views/show.html.erb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/generators/draft/resource/templates/views/show.html.erb b/lib/generators/draft/resource/templates/views/show.html.erb index f9a167b3..2eba63f0 100644 --- a/lib/generators/draft/resource/templates/views/show.html.erb +++ b/lib/generators/draft/resource/templates/views/show.html.erb @@ -1,8 +1,8 @@

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

    - + Edit <%= singular_table_name.humanize.downcase %> @@ -14,7 +14,7 @@ <%= attribute.human_name %>
    - <%%= @the_<%= singular_table_name %>.<%= attribute.column_name %> %> + <%%= @<%= singular_table_name %>_to_show.<%= attribute.column_name %> %>
    <% end -%> @@ -22,19 +22,19 @@ Created at
    - <%%= time_ago_in_words(@the_<%= singular_table_name %>.created_at) %> ago + <%%= time_ago_in_words(@<%= singular_table_name %>_to_show.created_at) %> ago
    Updated at
    - <%%= time_ago_in_words(@the_<%= singular_table_name %>.updated_at) %> ago + <%%= time_ago_in_words(@<%= singular_table_name %>_to_show.updated_at) %> ago
    <% unless read_only? -%> - + Delete <%= singular_table_name.humanize.downcase %> <% end -%>