Added routes, display seems to work so long as you remove the forms from the views.
[feedcatcher.git] / app / models / feed_item.rb
index ce5b8c6c05e674dd46de604e79797cfdad41d305..5b0e857b32da0fe488fa444f9fa53816da28e493 100644 (file)
@@ -1,21 +1,31 @@
 class FeedItem < ActiveRecord::Base
-
-  require 'cgi' # needed for url decoding
-
+  
+  def self.in_feed(name)
+    where('feed_name = ?', name)
+  end
+  
+  def self.entitled(title)
+    where('title = ?', title)
+  end
+  
   validates_presence_of :feed_name, :title, :description
+  validates_uniqueness_of :title, :scope => :feed_name
   validate :feed_name_must_be_legal
 
-protected
+  def FeedItem.valid_feed_name?(feed_name)
+    Rack::Utils::escape(feed_name) == feed_name and
+      Rack::Utils::unescape(feed_name) == feed_name and
+      feed_name != 'index' and
+      feed_name != 'show' and
+      feed_name != 'update' and
+      feed_name != 'action'
+  end
+
+  private
 
   def feed_name_must_be_legal
-    if url_encode(feed_name) != feed_name or
-        CGI::unescape(feed_name) != feed_name or
-        feed_name == 'index' or
-        feed_name == 'show' or
-        feed_name == 'update' or
-        feed_name == 'action'
-      errors.add(:feed_name, 'is an invalid feed name')
+    unless FeedItem.valid_feed_name?(feed_name)
+      errors.add(:feed_name, 'is invalid')
     end
   end
-
 end