Create followable concern, follow model. Add followable to proposal model.
This commit is contained in:
28
app/controllers/follows_controller.rb
Normal file
28
app/controllers/follows_controller.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class FollowsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
load_and_authorize_resource
|
||||
|
||||
def create
|
||||
@followable = find_followable
|
||||
@follow = Follow.create(user: current_user, followable: @followable)
|
||||
render :refresh_follow_button
|
||||
end
|
||||
|
||||
def destroy
|
||||
@follow = Follow.find(params[:id])
|
||||
@followable = @follow.followable
|
||||
@follow.destroy
|
||||
render :refresh_follow_button
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_followable
|
||||
params.each do |name, value|
|
||||
if name =~ /(.+)_id$/
|
||||
return $1.classify.constantize.find(value)
|
||||
end
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user