refactors debate and proposal flag actions
This commit is contained in:
20
app/controllers/concerns/flag_actions.rb
Normal file
20
app/controllers/concerns/flag_actions.rb
Normal 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
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user