2014-06-26 09:08:26 +02:00
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class CampaignsController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
|
|
|
|
load_and_authorize_resource :campaign, through: :conference
|
2014-06-26 09:08:26 +02:00
|
|
|
|
|
|
|
|
def index
|
2014-08-13 22:46:41 +03:00
|
|
|
authorize! :index, Campaign.new(conference_id: @conference.id)
|
2014-06-26 09:08:26 +02:00
|
|
|
@campaigns = @conference.campaigns
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2014-08-12 11:51:59 +03:00
|
|
|
@campaign.attributes = params[:campaign]
|
2014-06-26 09:08:26 +02:00
|
|
|
|
|
|
|
|
if @conference.save
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:notice] = 'Campaign successfully created.'
|
|
|
|
|
redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title))
|
2014-06-26 09:08:26 +02:00
|
|
|
else
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:error] = 'Campaign creation failed. ' + @campaign.errors.full_messages.to_sentence
|
|
|
|
|
render action: 'new'
|
2014-06-26 09:08:26 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-12 22:27:02 +03:00
|
|
|
def new; end
|
2014-06-26 09:08:26 +02:00
|
|
|
|
2014-08-12 22:27:02 +03:00
|
|
|
def edit; end
|
2014-06-26 09:08:26 +02:00
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
if @campaign.update_attributes(params[:campaign])
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:notice] = "Campaign '#{@campaign.name}' successfully updated."
|
|
|
|
|
redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title))
|
2014-06-26 09:08:26 +02:00
|
|
|
else
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:error] = "Campaign update failed. #{@campaign.errors.full_messages.to_sentence}"
|
|
|
|
|
render action: 'edit'
|
2014-06-26 09:08:26 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @campaign.destroy
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:notice] = "Campaign '#{@campaign.name}' successfully deleted."
|
|
|
|
|
redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title))
|
2014-06-26 09:08:26 +02:00
|
|
|
else
|
2014-12-18 13:38:40 +01:00
|
|
|
flash[:error] = "Delete of Campaign for #{@conference.short_title} failed." \
|
|
|
|
|
"#{@campaign.errors.full_messages.join('. ')}."
|
|
|
|
|
redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title))
|
2014-06-26 09:08:26 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|