Favor destroy_by over where.first&.destroy (#15868)

* Favor `destroy_by` over `where.first&.destroy`

We can use [ActiveRecord::Relation.destroy_by][1] instead of the method
chain.

[1]:https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-destroy_by

* Restoring custom behavior

Those constants are not ActiveRecord::Base objects, so don't implement
the method.
This commit is contained in:
Jeremy Friesen 2021-12-22 23:55:52 -05:00 committed by GitHub
parent 6d37f4303c
commit c7902a3261
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,7 +18,7 @@ class ProfilePinsController < ApplicationController
def update
# for removing pinnable
current_user.profile_pins.where(id: params[:id]).first&.destroy
current_user.profile_pins.destroy_by(id: params[:id])
bust_user_profile
flash[:pins_success] = "🗑 Pin removed"
redirect_back(fallback_location: "/dashboard")