refactors debate and proposal flag actions

This commit is contained in:
rgarcia
2015-09-28 16:33:23 +02:00
parent e7d1ae63d6
commit 6426bd3a29
3 changed files with 24 additions and 20 deletions

View File

@@ -0,0 +1,20 @@
module FlagActions
extend ActiveSupport::Concern
def flag
Flag.flag(current_user, flagable)
respond_with flagable, template: "#{controller_name}/_refresh_flag_actions"
end
def unflag
Flag.unflag(current_user, flagable)
respond_with flagable, template: "#{controller_name}/_refresh_flag_actions"
end
private
def flagable
instance_variable_get("@#{controller_name.singularize}")
end
end

View File

@@ -1,4 +1,6 @@
class DebatesController < ApplicationController class DebatesController < ApplicationController
include FlagActions
before_action :parse_tag_filter, only: :index before_action :parse_tag_filter, only: :index
before_action :parse_search_terms, only: :index before_action :parse_search_terms, only: :index
before_action :authenticate_user!, except: [:index, :show] before_action :authenticate_user!, except: [:index, :show]
@@ -62,16 +64,6 @@ class DebatesController < ApplicationController
set_debate_votes(@debate) set_debate_votes(@debate)
end end
def flag
Flag.flag(current_user, @debate)
respond_with @debate, template: 'debates/_refresh_flag_actions'
end
def unflag
Flag.unflag(current_user, @debate)
respond_with @debate, template: 'debates/_refresh_flag_actions'
end
private private
def debate_params def debate_params

View File

@@ -1,4 +1,6 @@
class ProposalsController < ApplicationController class ProposalsController < ApplicationController
include FlagActions
before_action :parse_tag_filter, only: :index before_action :parse_tag_filter, only: :index
before_action :parse_search_terms, only: :index before_action :parse_search_terms, only: :index
before_action :authenticate_user!, except: [:index, :show] before_action :authenticate_user!, except: [:index, :show]
@@ -62,16 +64,6 @@ class ProposalsController < ApplicationController
set_proposal_votes(@proposal) set_proposal_votes(@proposal)
end end
def flag
Flag.flag(current_user, @proposal)
respond_with @proposal, template: 'proposals/_refresh_flag_actions'
end
def unflag
Flag.unflag(current_user, @proposal)
respond_with @proposal, template: 'proposals/_refresh_flag_actions'
end
private private
def proposal_params def proposal_params