class CampaignsController < ApplicationController before_action :set_campaign, only: [:show, :edit, :update, :destroy] before_action :set_api_key def index @campaigns = Campaign.all end def show @campaign end def new @campaign = Campaign.new @campaign.videolistings.build @action = campaigns_path end def edit @action = campaign_path(@campaign.listingcode) end def create @campaign = Campaign.new campaign_params if @campaign.save respond_to do |format| format.json { render json: @campaign } format.html { redirect_to campaign_path(@campaign.listingcode), notice: 'Campaign was successfully created.' } end else respond_to do |format| format.json { render json: {error: @campaign.errors.full_messages } } format.html { render action: 'new' } end end end def update if @campaign.update(campaign_params) redirect_to campaign_path(@campaign.listingcode), notice: 'Campaign was successfully updated.' else respond_to do |format| format.json { render json: {error: @campaign.errors.full_messages } } format.html { render action: 'edit' } end end end def destroy @campaign.destroy redirect_to campaigns_url, notice: 'Campaign was successfully destroyed.' end private def set_campaign listingcode = params[:listingcode] if params[:campaign] @campaign = Campaign.find_by_listingcode(params[:campaign][:listingcode]) || not_found else @campaign = Campaign.find_by_listingcode(listingcode) || not_found end end def campaign_params 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, ]) end def not_found raise ActionController::RoutingError.new("Not Found by clientid") end def set_api_key @BETTER_VIDEO_API_KEY = ENV['BETTER_VIDEO_API_KEY'] @BETTER_VIDEO_API_KEY ||= "propel test key" end end