* Turn CacheBuster into a module This class used no internal state, so repeatedly creating short-lived objects seems wasteful. * Consistently use string interpolation and parenthesis * Destructure arrays into meaningful names, formatting * Fix request spec for internal classified listings controller Interestingly this works when asserting directly on the module, but not on a double. Asserting directly in the module seems sufficient for this test so the indirection was removed. * Turn CacheBuster into a module This class used no internal state, so repeatedly creating short-lived objects seems wasteful. * Fix specs after rebasing
37 lines
1.1 KiB
Ruby
37 lines
1.1 KiB
Ruby
class ProfilePinsController < ApplicationController
|
|
before_action :authenticate_user!, only: %i[create update]
|
|
|
|
def create
|
|
@profile_pin = ProfilePin.new
|
|
@profile_pin.profile_id = current_user.id
|
|
@profile_pin.profile_type = "User"
|
|
@profile_pin.pinnable_id = profile_pin_params[:pinnable_id].to_i
|
|
@profile_pin.pinnable_type = "Article"
|
|
if @profile_pin.save
|
|
flash[:pins_success] = "📌 Pinned! (pinned posts display chronologically, 5 max)"
|
|
else
|
|
flash[:pins_error] = "You can only have five pins"
|
|
end
|
|
redirect_back(fallback_location: "/dashboard")
|
|
bust_user_profile
|
|
end
|
|
|
|
def update
|
|
# for removing pinnable
|
|
current_user.profile_pins.where(id: params[:id]).first&.destroy
|
|
bust_user_profile
|
|
flash[:pins_success] = "🗑 Pin removed"
|
|
redirect_back(fallback_location: "/dashboard")
|
|
end
|
|
|
|
private
|
|
|
|
def profile_pin_params
|
|
params.require(:profile_pin).permit(:pinnable_id)
|
|
end
|
|
|
|
def bust_user_profile
|
|
CacheBuster.bust(current_user.path)
|
|
CacheBuster.bust("#{current_user.path}?i=i")
|
|
end
|
|
end
|