docbrown/app/controllers/profile_pins_controller.rb
Ben Halpern dcbb188cf1
Add pinned articles box to profiles (#3269)
* Initial pins work

* Add pin box to profiles

* Fix test snapshot spacing and optimize svg

* Fix listings spacing
2019-06-24 15:18:29 -04:00

30 lines
885 B
Ruby

class ProfilePinsController < ApplicationController
before_action :authenticate_user!, only: %i[create]
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")
end
def update
# for removing pinnable
ProfilePin.find(params[:id]).destroy
flash[:pins_success] = "🗑 Pin removed"
redirect_back(fallback_location: "/dashboard")
end
private
def profile_pin_params
params.require(:profile_pin).permit(:pinnable_id)
end
end