vidpush/app/controllers/campaigns_controller.rb
2014-04-09 17:39:48 -04:00

70 lines
2.0 KiB
Ruby

class CampaignsController < ApplicationController
before_action :set_campaign, only: [:show, :edit, :update, :destroy]
def index
@campaigns = Campaign.all
end
def show
respond_to do |format|
format.json { render json: @campaign }
format.html { render html: @campaign }
end
end
def new
@campaign = Campaign.new
@campaign.videolistings.build
end
def edit
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.clientid), notice: 'Campaign was successfully created.' }
end
else
render action: 'new'
end
end
def update
if @campaign.update(campaign_params)
redirect_to @campaign, notice: 'Campaign was successfully updated.'
else
render action: 'edit'
end
end
def destroy
@campaign.destroy
redirect_to campaigns_url, notice: 'Campaign was successfully destroyed.'
end
private
def set_campaign
@campaign = Campaign.find_by_clientid(params[:clientid]) || not_found
end
def campaign_params
params.require(:campaign).permit(:id, :clientid, :listingcode, :billingcode, :advertisername, :address1,
:address2, :city, :state, :zip, :emailaddress, :customerfirstname,
:customerlastname, :salesrep, :salesrepemail, :businessphone,
:contactphone, :websiteurl,
videolistings_attributes: [:id, :videocode, :producttypeid, :remoteassetsarchive,
:voiceoverselection, :musicselection, :clientprovidedscript,
:keywords, :focus, :notes, :asseturls,])
end
def not_found
raise ActionController::RoutingError.new("Not Found by clientid")
end
end