Skip to content

Instantly share code, notes, and snippets.

@timuruski
Created January 30, 2012 17:07
Show Gist options
  • Select an option

  • Save timuruski/1705460 to your computer and use it in GitHub Desktop.

Select an option

Save timuruski/1705460 to your computer and use it in GitHub Desktop.
class Post
def self.find_by_id(id)
self.new
end
def comments
CommentCollection.new
end
end
class Comment
attr_reader :title, :body
def initialize
@title = "Anonymous Comment"
@body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam non mauris at neque mollis pellentesque"
end
end
class CommentCollection
def find_by_id(id)
Comment.new
end
end
require './post'
require 'renee'
run Renee {
path('posts') do
var :int do |post_id|
post = Post.find_by_id(post_id)
path('comments') do
var :int do |comment_id|
comment = post.comments.find_by_id(comment_id)
get {
halt "#{comment.title} - #{comment.body}"
}
end
end
end
end
}
require './post'
require 'sinatra/base'
class MyApp < Sinatra::Base
get "/posts/:post_id/comments/:comment_id" do
post = Post.find_by_id(params[:post_id])
comment = post.comments.find_by_id(params[:comment_id])
"#{comment.title} - #{comment.body}"
end
end
run MyApp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment