Created
January 30, 2012 17:07
-
-
Save timuruski/1705460 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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