Show single blog entry.

This commit is contained in:
Andrew Tomaka 2012-05-05 00:08:02 -04:00
parent 08dff24760
commit 8796d28d28
2 changed files with 12 additions and 1 deletions

View file

@ -14,6 +14,7 @@ class BlogsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render :json => @blog } format.json { render :json => @blog }
end
end end
end end

View file

@ -1,9 +1,19 @@
class Blog < ActiveRecord::Base class Blog < ActiveRecord::Base
attr_accessible :title, :body, :release attr_accessible :title, :body, :release
validates :title, :presence => true, :length { minimum: 3 } validates :title, :presence => true, :length => { :minimum => 3 }
validates :body, :presence => true validates :body, :presence => true
def self.released def self.released
Blog.where("DATE(release) <= DATE(?)", Time.now).order("release DESC") Blog.where("DATE(release) <= DATE(?)", Time.now).order("release DESC")
end end
def self.get(id = nil)
return false if nil
blog = Blog.find(id)
return false if blog.release == nil
return blog
end
end end