From 8a637c5272bcd1572275b2ab66269b6af806803c Mon Sep 17 00:00:00 2001 From: Sean Dickinson Date: Sat, 31 Oct 2026 14:15:02 -0400 Subject: [PATCH 1/4] fix: show ordered links and games on the student home Render the student home from contents so games appear and contents.position drives order. Co-Authored-By: Claude Opus 5.5 --- app/controllers/student_homes_controller.rb | 2 +- .../student_homes/contentables/_game.html.erb | 4 ++++ .../student_homes/contentables/_link.html.erb | 8 +++++++ app/views/student_homes/index.html.erb | 10 ++------- .../student_homes_controller_test.rb | 22 ++++++++++++++++--- 5 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 app/views/student_homes/contentables/_game.html.erb create mode 100644 app/views/student_homes/contentables/_link.html.erb diff --git a/app/controllers/student_homes_controller.rb b/app/controllers/student_homes_controller.rb index 30386a7..25b94f6 100644 --- a/app/controllers/student_homes_controller.rb +++ b/app/controllers/student_homes_controller.rb @@ -9,7 +9,7 @@ def index .order("programs.name") @active_program = @classroom_programs.find { |cp| cp.id.to_s == params[:classroom_program_id] } || @classroom_programs.first @published_modules = if @active_program - @active_program.classroom_modules.published.includes(content_module: :links) + @active_program.classroom_modules.published.includes(content_module: { contents: :contentable }) else [] end diff --git a/app/views/student_homes/contentables/_game.html.erb b/app/views/student_homes/contentables/_game.html.erb new file mode 100644 index 0000000..854bd67 --- /dev/null +++ b/app/views/student_homes/contentables/_game.html.erb @@ -0,0 +1,4 @@ +<% game = content.contentable %> +
  • + <%= link_to game.title, play_game_path(game), class: "link inline-flex items-center gap-1" %> +
  • diff --git a/app/views/student_homes/contentables/_link.html.erb b/app/views/student_homes/contentables/_link.html.erb new file mode 100644 index 0000000..abe19a7 --- /dev/null +++ b/app/views/student_homes/contentables/_link.html.erb @@ -0,0 +1,8 @@ +<% link = content.contentable %> +
  • + <%= tag.a link.title + " ↗", + href: safe_external_url(link.url), + target: "_blank", + rel: "noopener noreferrer", + class: "link inline-flex items-center gap-1" %> +
  • diff --git a/app/views/student_homes/index.html.erb b/app/views/student_homes/index.html.erb index db4cd85..fcf3364 100644 --- a/app/views/student_homes/index.html.erb +++ b/app/views/student_homes/index.html.erb @@ -30,14 +30,8 @@
      - <% classroom_module.content_module.links.each do |link| %> -
    • - <%= tag.a link.title + " ↗", - href: safe_external_url(link.url), - target: "_blank", - rel: "noopener noreferrer", - class: "link inline-flex items-center gap-1" %> -
    • + <% classroom_module.content_module.contents.each do |content| %> + <%= render "student_homes/contentables/#{content.contentable_name}", content: content %> <% end %>
    diff --git a/test/controllers/student_homes_controller_test.rb b/test/controllers/student_homes_controller_test.rb index d7567a2..aa50aef 100644 --- a/test/controllers/student_homes_controller_test.rb +++ b/test/controllers/student_homes_controller_test.rb @@ -18,11 +18,21 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest assert_select "summary", text: /Introduction to Health/ end - test "shows links inside published modules" do + test "shows links and games inside published modules" do get student_homes_url assert_response :success - link = content_modules(:one).links.first - assert_select "a[target='_blank']", text: /#{link.title}/ if link + assert_select "li a[target='_blank'][href='#{links(:one).url}']", text: /#{links(:one).title}/ + assert_select "li a[href='#{play_game_path(games(:one))}']:not([target])", text: games(:one).title + end + + test "shows contents in position order" do + get student_homes_url + assert_equal [ games(:one).title, links(:one).title ], listed_titles + + contents(:one).move_down + + get student_homes_url + assert_equal [ links(:one).title, games(:one).title ], listed_titles end test "most recently published module has the open attribute" do @@ -79,4 +89,10 @@ class StudentHomesControllerTest < ActionDispatch::IntegrationTest get student_homes_url(classroom_program_id: enrollment.id) assert_select "a[role='tab'][aria-selected='true'][href*='classroom_program_id=#{enrollment.id}']" end + + private + + def listed_titles + css_select("details li a").map { |a| a.text.delete_suffix(" ↗") } + end end From fa9e5cdb8575cbd078cd9c849b743cc9c94b0cec Mon Sep 17 00:00:00 2001 From: Sean Dickinson Date: Sat, 31 Oct 2026 15:10:32 -0400 Subject: [PATCH 2/4] fix: use partial collection rendering --- app/views/student_homes/_contentable.html.erb | 16 ++++++++++++++++ .../student_homes/contentables/_game.html.erb | 4 ---- .../student_homes/contentables/_link.html.erb | 8 -------- app/views/student_homes/index.html.erb | 4 +--- 4 files changed, 17 insertions(+), 15 deletions(-) create mode 100644 app/views/student_homes/_contentable.html.erb delete mode 100644 app/views/student_homes/contentables/_game.html.erb delete mode 100644 app/views/student_homes/contentables/_link.html.erb diff --git a/app/views/student_homes/_contentable.html.erb b/app/views/student_homes/_contentable.html.erb new file mode 100644 index 0000000..4a913fc --- /dev/null +++ b/app/views/student_homes/_contentable.html.erb @@ -0,0 +1,16 @@ +<% case contentable %> +<% when Link %> +
  • + <%= tag.a contentable.title + " ↗", + href: safe_external_url(contentable.url), + target: "_blank", + rel: "noopener noreferrer", + class: "link inline-flex items-center gap-1" %> +
  • +<% when Game %> +
  • + <%= tag.a contentable.title, href: play_game_path(contentable), class: "link inline-flex items-center gap-1" %> +
  • +<% else %> + <% raise "Invalid contentable type" %> +<% end %> \ No newline at end of file diff --git a/app/views/student_homes/contentables/_game.html.erb b/app/views/student_homes/contentables/_game.html.erb deleted file mode 100644 index 854bd67..0000000 --- a/app/views/student_homes/contentables/_game.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<% game = content.contentable %> -
  • - <%= link_to game.title, play_game_path(game), class: "link inline-flex items-center gap-1" %> -
  • diff --git a/app/views/student_homes/contentables/_link.html.erb b/app/views/student_homes/contentables/_link.html.erb deleted file mode 100644 index abe19a7..0000000 --- a/app/views/student_homes/contentables/_link.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<% link = content.contentable %> -
  • - <%= tag.a link.title + " ↗", - href: safe_external_url(link.url), - target: "_blank", - rel: "noopener noreferrer", - class: "link inline-flex items-center gap-1" %> -
  • diff --git a/app/views/student_homes/index.html.erb b/app/views/student_homes/index.html.erb index fcf3364..7c94709 100644 --- a/app/views/student_homes/index.html.erb +++ b/app/views/student_homes/index.html.erb @@ -30,9 +30,7 @@
      - <% classroom_module.content_module.contents.each do |content| %> - <%= render "student_homes/contentables/#{content.contentable_name}", content: content %> - <% end %> + <%= render partial: "student_homes/contentable", collection: classroom_module.content_module.contents.map(&:contentable) %>
    <% end %> From 6fba7733c58f34897eeb88c5a611e69c8405623a Mon Sep 17 00:00:00 2001 From: Sean Dickinson Date: Sat, 31 Oct 2026 15:29:19 -0400 Subject: [PATCH 3/4] fix: partial renderer --- app/views/admin/content_modules/edit.html.erb | 5 +---- app/views/admin/contents/_content.html.erb | 22 +++++++++++++++++++ .../contents/contentables/_game.html.erb | 14 ------------ .../contents/contentables/_link.html.erb | 14 ------------ 4 files changed, 23 insertions(+), 32 deletions(-) create mode 100644 app/views/admin/contents/_content.html.erb delete mode 100644 app/views/admin/contents/contentables/_game.html.erb delete mode 100644 app/views/admin/contents/contentables/_link.html.erb diff --git a/app/views/admin/content_modules/edit.html.erb b/app/views/admin/content_modules/edit.html.erb index 1f67ca9..db9e96f 100644 --- a/app/views/admin/content_modules/edit.html.erb +++ b/app/views/admin/content_modules/edit.html.erb @@ -42,10 +42,7 @@ - <% @contents.each_with_index do |content, index| %> - <%= render "admin/contents/contentables/#{content.contentable_name}", content: content, - first: index.zero?, last: index == @contents.size - 1 %> - <% end %> + <%= render partial: "admin/contents/content", collection: @contents %> <% else %> diff --git a/app/views/admin/contents/_content.html.erb b/app/views/admin/contents/_content.html.erb new file mode 100644 index 0000000..6cc6c43 --- /dev/null +++ b/app/views/admin/contents/_content.html.erb @@ -0,0 +1,22 @@ +<%# locals: (content:, content_iteration:) %> +<% contentable = content.contentable %> + + <% case contentable %> + <% when Link %> + <%= link_to "#{contentable.title} ↗", safe_external_url(contentable.url), target: "_blank", rel: "noopener noreferrer", class: "link inline-flex items-center gap-1" %> + <%= contentable.link_type.humanize %> + <% when Game %> + <%= contentable.title %> + Game + <% end %> + +
    + <%= render "admin/shared/move_buttons", url: admin_content_position_path(content), title: contentable.title, + first: content_iteration.first?, last: content_iteration.last? %> + <%= link_to "Edit", edit_polymorphic_path([:admin, contentable]), class: "btn btn-xs btn-primary" %> + <%= button_to "Remove", admin_content_path(content), method: :delete, + data: { "turbo-confirm": "Remove this item from the module?" }, + class: "btn btn-xs btn-error" %> +
    + + diff --git a/app/views/admin/contents/contentables/_game.html.erb b/app/views/admin/contents/contentables/_game.html.erb deleted file mode 100644 index 3da5573..0000000 --- a/app/views/admin/contents/contentables/_game.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<% game = content.contentable %> - - <%= game.title %> - Game - -
    - <%= render "admin/shared/move_buttons", url: admin_content_position_path(content), title: game.title, first: first, last: last %> - <%= link_to "Edit", edit_admin_game_path(game), class: "btn btn-xs btn-primary" %> - <%= button_to "Remove", admin_content_path(content), method: :delete, - data: { "turbo-confirm": "Remove this game from the module?" }, - class: "btn btn-xs btn-error" %> -
    - - diff --git a/app/views/admin/contents/contentables/_link.html.erb b/app/views/admin/contents/contentables/_link.html.erb deleted file mode 100644 index 3d6349a..0000000 --- a/app/views/admin/contents/contentables/_link.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<% link = content.contentable %> - - <%= link_to "#{link.title} ↗", safe_external_url(link.url), target: "_blank", rel: "noopener noreferrer", class: "link inline-flex items-center gap-1" %> - <%= link.link_type.humanize %> - -
    - <%= render "admin/shared/move_buttons", url: admin_content_position_path(content), title: link.title, first: first, last: last %> - <%= link_to "Edit", edit_admin_link_path(link), class: "btn btn-xs btn-primary" %> - <%= button_to "Delete", admin_content_path(content), method: :delete, - data: { "turbo-confirm": "Delete this link?" }, - class: "btn btn-xs btn-error" %> -
    - - From 880e504d611e86d3e5756f763a97cc682d3e09e6 Mon Sep 17 00:00:00 2001 From: Sean Dickinson Date: Sat, 31 Oct 2026 15:50:07 -0400 Subject: [PATCH 4/4] chore: lint --- app/views/student_homes/_contentable.html.erb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/student_homes/_contentable.html.erb b/app/views/student_homes/_contentable.html.erb index 4a913fc..06aa00e 100644 --- a/app/views/student_homes/_contentable.html.erb +++ b/app/views/student_homes/_contentable.html.erb @@ -11,6 +11,4 @@
  • <%= tag.a contentable.title, href: play_game_path(contentable), class: "link inline-flex items-center gap-1" %>
  • -<% else %> - <% raise "Invalid contentable type" %> -<% end %> \ No newline at end of file +<% end %>