Fix most design flaws
[b4.git] / app / models / link.rb
blobc9dd2cce230b273f784c676cb301f123078eaea0
1 require 'uri'
3 class Link < ActiveRecord::Base
4   attr_accessible :title, :url, :user_id
5   belongs_to :user
6   acts_as_taggable
8   validates :user_id, presence: true
9   validates :url, presence: true
11   validates :url, :format => URI::regexp(%w(http https))
12   validates :title, :format => /\S/
14   default_scope order: 'links.created_at DESC'
16   def serializable_hash(options=nil)
17     options ||= {}
18     super(options).merge({"tags" => self.tag_list})
19   end
20 end