Create followable concern, follow model. Add followable to proposal model.

This commit is contained in:
Senén Rodero Rodríguez
2017-06-26 20:36:09 +02:00
parent e8e6eff679
commit 84dbef16a4
18 changed files with 372 additions and 4 deletions

View 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