Skip to content

Commit

Permalink
fix videos
Browse files Browse the repository at this point in the history
  • Loading branch information
jodyalbritton committed Jul 20, 2014
1 parent 64e5375 commit e3f7576
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
19 changes: 16 additions & 3 deletions app/models/video.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
class Video < ActiveRecord::Base
before_save :update_details
require 'open-uri'
attr_reader :thumbnail_remote_url
before_validation :update_details
after_create :thumbnail_remote_url
searchkick autocomplete: ['title']
extend FriendlyId
friendly_id :title, use: :slugged
include Rails.application.routes.url_helpers
belongs_to :sponsor
belongs_to :category
acts_as_taggable # Alias for acts_as_taggable_on

has_attached_file :thumbnail, :styles => { :large => "750x450#", :medium => "360x244#", :thumb => "100x100#" }, :default_url => ":style/missing.png"
validates_attachment_content_type :thumbnail, :content_type => /\Aimage\/.*\Z/

YT_LINK_FORMAT = /\A.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*\z/i

Expand All @@ -28,6 +32,14 @@ class Video < ActiveRecord::Base
end

validates :link, presence: true, format: YT_LINK_FORMAT

def thumbnail_remote_url
thumb_url = 'http://img.youtube.com/vi/'+self.uid+'/hqdefault.jpg'
self.thumbnail = open(thumb_url)



end

def get_share_url
video_url(self)
Expand Down Expand Up @@ -114,7 +126,8 @@ def update_details
def should_generate_new_friendly_id?
slug.blank?
end



end
def parse_duration(d)
hr = (d / 3600).floor
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140720180943_add_thumbnail_to_videos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddThumbnailToVideos < ActiveRecord::Migration
def change
add_attachment :videos, :thumbnail
end
end
12 changes: 8 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140719191720) do
ActiveRecord::Schema.define(version: 20140720180943) do

create_table "attachments", force: true do |t|
t.integer "attachable_id"
Expand Down Expand Up @@ -641,20 +641,24 @@
t.datetime "updated_at"
t.string "uid"
t.integer "category_id"
t.boolean "featured", default: true
t.boolean "listed", default: true
t.boolean "featured", default: true
t.boolean "listed", default: true
t.string "yt_tags"
t.integer "views"
t.integer "position"
t.datetime "published_at"
t.datetime "yt_updated_at"
t.string "slug"
t.integer "sponsor_id"
t.boolean "sponsored", default: false
t.boolean "sponsored", default: false
t.text "embed"
t.string "url"
t.text "description"
t.integer "gallery_id"
t.string "thumbnail_file_name"
t.string "thumbnail_content_type"
t.integer "thumbnail_file_size"
t.datetime "thumbnail_updated_at"
end

add_index "videos", ["category_id"], name: "index_videos_on_category_id", using: :btree
Expand Down

0 comments on commit e3f7576

Please sign in to comment.