Class: CampaignsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/campaigns_controller.rb

Overview

Managing campaigns

Instance Method Summary collapse

Instance Method Details

#candidateObject

get /campaigns/:id/candidate-:candidate_id



31
32
# File 'app/controllers/campaigns_controller.rb', line 31

def candidate
end

#checkObject

post /campaigns/check



13
14
15
16
17
# File 'app/controllers/campaigns_controller.rb', line 13

def check
  @entity = Campaign.instance_for_check(params[:entity_id], entity_parameters)

  render 'shared/forms/check'
end

#createObject

post /campaigns



67
68
69
70
71
72
73
74
75
# File 'app/controllers/campaigns_controller.rb', line 67

def create
  @entity = Campaign.new(entity_parameters)
  if @entity.save
    NetworkCampaignSyncJob.perform_later(@entity.id)
    form_processed_ok(admin_campaign_path(id: @entity.id))
  else
    form_processed_with_error(:new)
  end
end

#destroyObject

delete /campaigns/:id



92
93
94
95
96
# File 'app/controllers/campaigns_controller.rb', line 92

def destroy
  flash[:notice] = t('campaigns.destroy.success') if @entity.destroy

  redirect_to(admin_campaigns_path)
end

#editObject

get /campaigns/:id/edit



78
79
# File 'app/controllers/campaigns_controller.rb', line 78

def edit
end

#eventObject

get /campaigns/:id/event-:event_id



55
56
57
58
59
# File 'app/controllers/campaigns_controller.rb', line 55

def event
  @event = @entity.events.list_for_visitors.find_by(id: params[:event_id])

  handle_http_404('Cannot find event for campaign') if @event.nil?
end

#indexObject

get /campaigns



20
21
22
# File 'app/controllers/campaigns_controller.rb', line 20

def index
  @collection = Campaign.list_for_visitors
end

#join_teamObject

post /campaigns/:id/candidate-:candidate_id/join



47
48
49
50
51
52
# File 'app/controllers/campaigns_controller.rb', line 47

def join_team
  role = param_from_request(:role)
  @candidate.add_user(current_user, role)

  render json: { meta: { message: t('campaigns.join_team.pending') } }
end

#mandateObject

get /campaigns/:id/mandate-:mandate_id



35
36
37
38
39
# File 'app/controllers/campaigns_controller.rb', line 35

def mandate
  @mandate = @entity.mandates.list_for_visitors.find_by(id: params[:mandate_id])

  handle_http_404('Cannot find mandate for campaign') if @mandate.nil?
end

#mandatesObject

get /campaigns/:id/candidate-:candidate_id/mandates



42
43
44
# File 'app/controllers/campaigns_controller.rb', line 42

def mandates
  @collection = @candidate.mandates.list_for_visitors # .page(current_page)
end

#newObject

get /campaigns/new



62
63
64
# File 'app/controllers/campaigns_controller.rb', line 62

def new
  @entity = Campaign.new
end

#showObject

get /campaigns/:id



25
26
27
28
# File 'app/controllers/campaigns_controller.rb', line 25

def show
  @entity = Campaign.list_for_visitors.find_by(slug: params[:id])
  handle_http_404('Cannot find campaign') if @entity.nil?
end

#updateObject

patch /campaigns/:id



82
83
84
85
86
87
88
89
# File 'app/controllers/campaigns_controller.rb', line 82

def update
  if @entity.update(entity_parameters)
    NetworkCampaignSyncJob.perform_later(@entity.id, false)
    form_processed_ok(admin_campaign_path(id: @entity.id))
  else
    form_processed_with_error(:edit)
  end
end