lib/models.rb in cachai-0.0.3 vs lib/models.rb in cachai-0.0.4
- old
+ new
@@ -27,9 +27,13 @@
class Post < ActiveRecord::Base
has_many :responses
validates_presence_of :path
validates_uniqueness_of :path
+
+ def self.find_or_create_by_path(path)
+ find_by_path(path) || create({:path => path})
+ end
end
class Response < ActiveRecord::Base
belongs_to :post
validates_presence_of :author_name, :author_name, :author_email, :content