Skip to content

Commit 50c5e4f

Browse files
committed
example of mounting an async Sinatra app under rails 3
1 parent fb9ce25 commit 50c5e4f

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
source 'http://rubygems.org'
22

33
gem 'rails', '3.0.0.beta4'
4+
gem 'sinatra'
45

56
# async wrappers
67
gem 'rack-fiber_pool', :require => 'rack/fiber_pool'

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Simple async demo stack with Rails 3 + EventMachine and Fibers.
44

55
* Hit localhost:3000/widgets to do a 1s async mysql query
66
* Hit localhost:3000/widgets/http to make an HTTP call back to /widgets - recursive! :-)
7+
* Hit localhost:3000/twitter to load a mounted async Sinatra app (reports latests rails 3 tweets)
78

89
Requirements:
910

app/metal/twitter.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Twitter < Sinatra::Base
2+
get '/twitter' do
3+
http = EM::HttpRequest.new("http://search.twitter.com/search?q=rails+3&format=json").get
4+
tweets = ActiveSupport::JSON.decode(http.response)
5+
tweets = tweets['results'].collect {|t| t['text'] }.join("</br>")
6+
tweets
7+
end
8+
end

config/routes.rb

+4
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,9 @@
5454

5555
# This is a legacy wild controller route that's not recommended for RESTful applications.
5656
# Note: This route will make all actions in every controller accessible via GET requests.
57+
58+
# mount async sinatra app (in metal folder)
59+
match '/twitter', :to => Twitter
60+
5761
match ':controller(/:action(/:id(.:format)))'
5862
end

0 commit comments

Comments
 (0)