0
0
Fork 0

get the comments as json

This commit is contained in:
Gibheer 2011-07-05 19:18:11 +02:00
parent 0debfef42f
commit 700d42fe54
3 changed files with 18 additions and 0 deletions

View File

@ -12,4 +12,14 @@ class Comment
validates_presence_of :author, :email, :body
validates_length_of :email, :min => 3, :max => 100
validates_format_of :email, :with => :email_address
# overwrite the default to_json, because we don't need all fields
def to_json ressource_options
{
:id => id,
:post_id => post.id,
:author => author,
:body => body
}
end
end

View File

@ -15,4 +15,8 @@ class Post
def self.get_released id
first(:id => id, :released => true)
end
def acknowledged_comments
comments(:acknowledged => true)
end
end

View File

@ -19,6 +19,10 @@ class Blog < Sinatra::Base
end
end
get '/post/:id/comment.json' do
Post.get_released(params[:id]).acknowledged_comments.to_json
end
get '/stylesheet.css' do
scss :stylesheet
end