Move YoutubeTitles callback into module

This commit is contained in:
Raphael Sofaer 2011-05-29 18:28:07 -07:00
parent 1be2845687
commit 71c3a29aa6
4 changed files with 9 additions and 5 deletions

View file

@ -25,7 +25,6 @@ class Comment < ActiveRecord::Base
serialize :youtube_titles, Hash
before_save do
get_youtube_title text
self.text.strip! unless self.text.nil?
end
def diaspora_handle

View file

@ -71,7 +71,7 @@ class Request
private
def not_already_connected
if sender && recipient && Contact.where(:user_id => self.recipient.owner_id, :person_id => self.sender.id).count > 0
if sender && recipient && Contact.where(:user_id => self.recipient.owner_id, :person_id => self.sender.id).exists?
errors[:base] << 'You have already connected to this person'
end
end

View file

@ -23,9 +23,6 @@ class StatusMessage < Post
attr_accessible :text
serialize :youtube_titles, Hash
before_save do
get_youtube_title text
end
before_create :build_tags

View file

@ -1,4 +1,12 @@
module YoutubeTitles
def self.included(model)
model.class_eval do
before_save do
get_youtube_title text
end
end if model.respond_to?(:before_save)
end
def youtube_title_for video_id
http = Net::HTTP.new('gdata.youtube.com', 80)
path = "/feeds/api/videos/#{video_id}?v=2"