Created
August 4, 2009 19:09
-
-
Save rmanalan/161461 to your computer and use it in GitHub Desktop.
How to embed a Sinatra app inside a Rails app through a plugin (not Metal)
This file contains 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
script/generate plugin HelloWorld | |
# vendor/plugins/hello_world/init.rb | |
Rails.configuration.gem "sinatra" | |
Rails.configuration.middleware.insert_before("ActionController::Failsafe", "HelloWorld") | |
# vendor/plugins/hello_world/lib/hello_world.rb | |
# your sinatra app goes here... | |
require 'sinatra/base' | |
class HelloWorld < Sinatra::Base | |
get "/hello" do | |
"Hello World!" | |
end | |
#this hackeration is required for sinatra to be a nice rack citizen | |
error 404 do | |
@app.call(env) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cobbr2 I'm not entirely sure this is required anymore. This is old 2.3.x stuff... not sure if it's useful in rails 3 or even newer versions of rack and sinatra. I wrote this pre-sinatra 1.0