2014-04-07 18:41:34 +00:00
|
|
|
class CampaignsController < ApplicationController
|
|
|
|
before_action :set_campaign, only: [:show, :edit, :update, :destroy]
|
2014-04-21 15:07:45 +00:00
|
|
|
before_action :set_api_key
|
2014-04-07 18:41:34 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@campaigns = Campaign.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2014-04-21 15:07:45 +00:00
|
|
|
# respond_to do |format|
|
|
|
|
# format.json { render json: @campaign, include: [:videolistings,] }
|
|
|
|
# format.html { render html: @campaign }
|
|
|
|
# end
|
|
|
|
@campaign
|
2014-04-07 18:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@campaign = Campaign.new
|
2014-04-09 15:06:07 +00:00
|
|
|
@campaign.videolistings.build
|
2014-04-15 20:59:07 +00:00
|
|
|
@action = campaigns_path
|
2014-04-07 18:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2014-04-15 20:59:07 +00:00
|
|
|
@action = campaign_path(@campaign.clientid)
|
|
|
|
|
2014-04-07 18:41:34 +00:00
|
|
|
end
|
|
|
|
|
2014-04-09 21:39:48 +00:00
|
|
|
|
2014-04-07 18:41:34 +00:00
|
|
|
def create
|
2014-04-09 15:06:07 +00:00
|
|
|
@campaign = Campaign.new campaign_params
|
2014-04-08 20:02:51 +00:00
|
|
|
|
2014-04-07 18:41:34 +00:00
|
|
|
if @campaign.save
|
2014-04-08 19:27:38 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: @campaign }
|
2014-04-09 21:39:48 +00:00
|
|
|
format.html { redirect_to campaign_path(@campaign.clientid), notice: 'Campaign was successfully created.' }
|
2014-04-08 19:27:38 +00:00
|
|
|
end
|
2014-04-07 18:41:34 +00:00
|
|
|
else
|
|
|
|
render action: 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @campaign.update(campaign_params)
|
2014-04-15 17:04:58 +00:00
|
|
|
redirect_to campaign_path(@campaign.clientid), notice: 'Campaign was successfully updated.'
|
2014-04-07 18:41:34 +00:00
|
|
|
else
|
|
|
|
render action: 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@campaign.destroy
|
|
|
|
redirect_to campaigns_url, notice: 'Campaign was successfully destroyed.'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def set_campaign
|
2014-04-09 15:06:07 +00:00
|
|
|
@campaign = Campaign.find_by_clientid(params[:clientid]) || not_found
|
2014-04-07 18:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def campaign_params
|
2014-04-21 15:07:45 +00:00
|
|
|
params.require(:campaign).permit(:id, :address, :advertisername, :awards, :background, :billingcode,
|
|
|
|
:businessphone, :categories, :city, :clientid, :companycolors, :contactphone,
|
|
|
|
:customerfirstname, :customerlastname, :description, :emailaddress, :facebookurl,
|
|
|
|
:listingcode, :productsandservices, :state, :targetaudience, :tollfreephone,
|
|
|
|
:vpa, :websiteurl, :zip,
|
|
|
|
videolistings_attributes: [:id, :asseturls, :clientprovidedscript, :focus,
|
|
|
|
:keywords, :musicselection, :notes, :producttypeid,
|
|
|
|
:videocode, :voiceoverselection,
|
|
|
|
])
|
2014-04-08 19:27:38 +00:00
|
|
|
end
|
|
|
|
|
2014-04-09 15:06:07 +00:00
|
|
|
def not_found
|
|
|
|
raise ActionController::RoutingError.new("Not Found by clientid")
|
|
|
|
end
|
2014-04-09 18:12:14 +00:00
|
|
|
|
2014-04-21 15:07:45 +00:00
|
|
|
|
|
|
|
def set_api_key
|
|
|
|
@BETTER_VIDEO_API_KEY = ENV['BETTER_VIDEO_API_KEY']
|
|
|
|
@BETTER_VIDEO_API_KEY ||= "propel test key"
|
|
|
|
end
|
2014-04-07 18:41:34 +00:00
|
|
|
end
|