From 671e66bf531d4baf3f49cb6bcc4f5803d20ae1b5 Mon Sep 17 00:00:00 2001 From: Patrick McKernin Date: Mon, 10 Aug 2020 14:59:01 -0500 Subject: [PATCH] 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 9aac7e9..a7766f4 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