vidpush/app/controllers/campaigns_controller.rb

73 lines
2.1 KiB
Ruby
Raw Normal View History

2014-04-07 18:41:34 +00:00
class CampaignsController < ApplicationController
before_action :set_campaign, only: [:show, :edit, :update, :destroy]
def index
@campaigns = Campaign.all
end
def show
respond_to do |format|
2014-04-18 19:34:44 +00:00
format.json { render json: @campaign, include: [:videolistings,] }
format.html { render html: @campaign }
end
2014-04-07 18:41:34 +00:00
end
def new
@campaign = Campaign.new
@campaign.videolistings.build
@action = campaigns_path
2014-04-07 18:41:34 +00:00
end
def edit
@action = campaign_path(@campaign.clientid)
2014-04-07 18:41:34 +00:00
end
2014-04-07 18:41:34 +00:00
def create
@campaign = Campaign.new campaign_params
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 }
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
@campaign = Campaign.find_by_clientid(params[:clientid]) || not_found
2014-04-07 18:41:34 +00:00
end
def campaign_params
params.require(:campaign).permit(:id, :clientid, :listingcode, :billingcode, :advertisername, :address1,
2014-04-08 19:27:38 +00:00
: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,])
2014-04-08 19:27:38 +00:00
end
def not_found
raise ActionController::RoutingError.new("Not Found by clientid")
end
2014-04-07 18:41:34 +00:00
end