docbrown/app/controllers/profile_pins_controller.rb
Alex b02d43ca2d
Create DiscussionLocks (#13905)
* Create DiscussionLocks

* Fix specs

* Update nullify_blank_notes_and_reason

* Update before_validation call

* Updated DiscussionLockPolicy for clarity

* Move permitted_attributes to a constant

* Update route

* Apply suggestions from code review for frontend

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* Add title tags

* Wrap unlock confirm in main element

* Wrap flash messages up in div

* Actually fix title tags

* Hide comment reply button when discussion is locked

* Add E2E tests

* Try to fix E2E tests

* Cypress...you work locally but not in CI...why!?

* PR feedback

* Update E2E tests

* More E2E updates 😭

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
2021-06-10 11:04:33 -04:00

38 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[:success] = "📌 Pinned! (pinned posts display chronologically, 5 max)"
else
flash[: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
cache_bust = EdgeCache::Bust.new
cache_bust.call(current_user.path)
cache_bust.call("#{current_user.path}?i=i")
end
end