Create 'poll_question_answer_videos' table and model
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
class Poll::Question::Answer < ActiveRecord::Base
|
||||
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id'
|
||||
has_many :videos, class_name: 'Poll::Question::Answer::Video'
|
||||
|
||||
validates :title, presence: true
|
||||
|
||||
|
||||
16
app/models/poll/question/answer/video.rb
Normal file
16
app/models/poll/question/answer/video.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class Poll::Question::Answer::Video < ActiveRecord::Base
|
||||
belongs_to :answer, class_name: 'Poll::Question::Answer', foreign_key: 'answer_id'
|
||||
|
||||
VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/
|
||||
YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
|
||||
|
||||
validates :title, presence: true
|
||||
validate :valid_url?
|
||||
|
||||
def valid_url?
|
||||
return if url.blank?
|
||||
return if url.match(VIMEO_REGEX)
|
||||
return if url.match(YOUTUBE_REGEX)
|
||||
errors.add(:url, :invalid)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user