Skip to content

Instantly share code, notes, and snippets.

@rmanalan
Created August 4, 2009 19:09
Show Gist options
  • Save rmanalan/161461 to your computer and use it in GitHub Desktop.
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)
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
@rmanalan
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment