validate uniqueness, don't allow duplicate campaigns.
This commit is contained in:
parent
dd0c0e4ab0
commit
ab906fdd00
@ -22,7 +22,9 @@ class CampaignsController < ApplicationController
|
||||
|
||||
# POST /campaigns
|
||||
def create
|
||||
@campaign = Campaign.new(campaign_params)
|
||||
clientid = campaign_params.delete(:clientid)
|
||||
@campaign = Campaign.find_or_create_by(clientid: clientid)
|
||||
@campaign.update(campaign_params)
|
||||
|
||||
if @campaign.save
|
||||
respond_to do |format|
|
||||
@ -57,11 +59,11 @@ class CampaignsController < ApplicationController
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def campaign_params
|
||||
params.require(:campaign).permit(:clientid, :listingcode, :billingcode, :advertisername, :address1,
|
||||
params.require(:campaign).permit(:id, :clientid, :listingcode, :billingcode, :advertisername, :address1,
|
||||
:address2, :city, :state, :zip, :emailaddress, :customerfirstname,
|
||||
:customerlastname, :salesrep, :salesrepemail, :businessphone,
|
||||
:contactphone, :websiteurl,
|
||||
videolistings_attributes: [:videocode, :producttypeid, :remoteassetsarchive, :voiceoverselection,
|
||||
videolistings_attributes: [:id, :videocode, :producttypeid, :remoteassetsarchive, :voiceoverselection,
|
||||
:musicselection, :clientprovidedscript, :keywords, :focus, :notes, :asseturls,])
|
||||
end
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
class Campaign < ActiveRecord::Base
|
||||
has_many :videolistings
|
||||
accepts_nested_attributes_for :videolistings
|
||||
validates :clientid, presence: true, uniqueness: true
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
class Videolisting < ActiveRecord::Base
|
||||
belongs_to :campaign
|
||||
validates :videocode, presence: true, uniqueness: true
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user