From e69c1bd0a1d0859217021bc05e4e1e260e67f1f1 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 5 Apr 2025 15:45:16 +0200 Subject: [PATCH] Break pins out of the double nesting Its cumbersome and needless --- app/controllers/bubbles/pins_controller.rb | 4 ++-- app/views/bubbles/pins/show.html.erb | 4 ++-- app/views/bubbles/show.html.erb | 2 +- config/routes.rb | 8 ++++++-- test/controllers/bubbles/pins_controller_test.rb | 8 ++++---- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/app/controllers/bubbles/pins_controller.rb b/app/controllers/bubbles/pins_controller.rb index fda94c937..09ac6b9c1 100644 --- a/app/controllers/bubbles/pins_controller.rb +++ b/app/controllers/bubbles/pins_controller.rb @@ -8,14 +8,14 @@ class Bubbles::PinsController < ApplicationController pin = @bubble.pin_by Current.user broadcast_new pin - redirect_to bucket_bubble_pin_path(@bucket, @bubble) + redirect_to bubble_pin_path(@bubble) end def destroy pin = @bubble.unpin_by Current.user broadcast_removed pin - redirect_to bucket_bubble_pin_path(@bucket, @bubble) + redirect_to bubble_pin_path(@bubble) end private diff --git a/app/views/bubbles/pins/show.html.erb b/app/views/bubbles/pins/show.html.erb index cbd2b75a0..5a8852a03 100644 --- a/app/views/bubbles/pins/show.html.erb +++ b/app/views/bubbles/pins/show.html.erb @@ -1,11 +1,11 @@ <%= turbo_frame_tag dom_id(@bubble, :pin) do %> <% if @bubble.pinned_by? Current.user %> - <%= button_to bucket_bubble_pin_path(@bubble.bucket, @bubble), method: :delete, class: "btn btn--reversed" do %> + <%= button_to bubble_pin_path(@bubble), method: :delete, class: "btn btn--reversed" do %> <%= icon_tag "pinned" %> Un-pin this card <% end %> <% else %> - <%= button_to bucket_bubble_pin_path(@bubble.bucket, @bubble), class: "btn" do %> + <%= button_to bubble_pin_path(@bubble), class: "btn" do %> <%= icon_tag "unpinned" %> Pin this card <% end %> diff --git a/app/views/bubbles/show.html.erb b/app/views/bubbles/show.html.erb index c88a0f625..b7d62b740 100644 --- a/app/views/bubbles/show.html.erb +++ b/app/views/bubbles/show.html.erb @@ -81,7 +81,7 @@ <% if @bubble.published? %>
<%= turbo_frame_tag dom_id(@bubble, :watch), src: bucket_bubble_watch_path(@bubble.bucket, @bubble), refresh: :morph %> - <%= turbo_frame_tag dom_id(@bubble, :pin), src: bucket_bubble_pin_path(@bubble.bucket, @bubble), refresh: :morph %> + <%= turbo_frame_tag dom_id(@bubble, :pin), src: bubble_pin_path(@bubble), refresh: :morph %>
<% end %> diff --git a/config/routes.rb b/config/routes.rb index 2b9b15d91..3433bc802 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,7 +17,12 @@ Rails.application.routes.draw do route_for :bucket_bubble, comment.bubble.bucket, comment.bubble, options end - resources :bubbles + resources :bubbles do + scope module: :bubbles do + resource :pin + end + end + resources :notifications, only: :index namespace :notifications do resource :tray, only: :show @@ -54,7 +59,6 @@ Rails.application.routes.draw do resource :recover resources :stagings resource :watch - resource :pin, only: [ :show, :create, :destroy ] end resources :assignments diff --git a/test/controllers/bubbles/pins_controller_test.rb b/test/controllers/bubbles/pins_controller_test.rb index cdde4e7f2..c4a6c3c0e 100644 --- a/test/controllers/bubbles/pins_controller_test.rb +++ b/test/controllers/bubbles/pins_controller_test.rb @@ -9,23 +9,23 @@ class Bubbles::PinsControllerTest < ActionDispatch::IntegrationTest assert_changes -> { bubbles(:layout).pinned_by?(users(:kevin)) }, from: false, to: true do perform_enqueued_jobs do assert_turbo_stream_broadcasts([ users(:kevin), :pins ], count: 1) do - post bucket_bubble_pin_path(buckets(:writebook), bubbles(:layout)) + post bubble_pin_path(bubbles(:layout)) end end end - assert_redirected_to bucket_bubble_pin_path(buckets(:writebook), bubbles(:layout)) + assert_redirected_to bubble_pin_path(bubbles(:layout)) end test "destroy" do assert_changes -> { bubbles(:shipping).pinned_by?(users(:kevin)) }, from: true, to: false do perform_enqueued_jobs do assert_turbo_stream_broadcasts([ users(:kevin), :pins ], count: 1) do - delete bucket_bubble_pin_path(buckets(:writebook), bubbles(:shipping)) + delete bubble_pin_path(bubbles(:shipping)) end end end - assert_redirected_to bucket_bubble_pin_path(buckets(:writebook), bubbles(:shipping)) + assert_redirected_to bubble_pin_path(bubbles(:shipping)) end end