Validations for at least one video listing

This commit is contained in:
Tyrel Souza 2014-04-24 15:47:47 -04:00
parent 1acbe34d77
commit e7c66e9c16
4 changed files with 22 additions and 4 deletions

View File

@ -7,7 +7,7 @@ class VideolistingsController < ApplicationController
elsif @videolisting.campaign.processed?
@videolisting.published = true
@videolisting.save
#TODO: SEND OUT EMAIL HERE.
@message = "Campaign Published Successfully."
else
@message = "Error: Campaign Not Published."
@ -29,4 +29,7 @@ class VideolistingsController < ApplicationController
def videolisting_params
params.require(:videolisting).permit(:videocode, :producttypeid, :remoteassetsarchive, :voiceoverselection, :musicselection, :clientprovidedscript, :keywords, :focus, :notes, :asseturls)
end
end

View File

@ -6,15 +6,23 @@ class Campaign < ActiveRecord::Base
validates :websiteurl, presence: true
validates :description, presence: true
validates :productsandservices, presence: true
after_save :send_to_better_video
validate :has_at_least_one_videolisting
def has_at_least_one_videolisting
errors.add(:base, 'Must add at least one Videolisting') if self.videolistings.blank?
end
def init
self.clientid = 720
end
after_create :send_to_better_video
def send_to_better_video
#TODO Make API Calls
if self.processed_changed? && self.processed == true
#TODO Make API Calls
end
end
end

View File

@ -3,6 +3,7 @@ class Videolisting < ActiveRecord::Base
validates :videocode, presence: true, uniqueness: true
validates :voiceoverselection, presence: true
validates :musicselection, presence: true
after_save :send_notification_after_change
def init
self.producttypeid = 721
@ -12,4 +13,10 @@ class Videolisting < ActiveRecord::Base
def asseturls_array
self.asseturls.split(',').collect { |url| { asseturl: url.strip } }
end
def send_notification_after_change
if self.published_changed? && self.published == true
#TODO: SEND OUT EMAIL HERE.
end
end
end

View File

@ -20,7 +20,7 @@
<span><%= videolisting.notes %></span>
</span>
<span class="videolisting-item">
<strong>asseturls</strong>
<strong>Asset URLs</strong>
<% videolisting.asseturls_array.each do |asset| %>
<span class="list-item"><%= asset[:asseturl] %></span>