Skip to content
Karol Bucek edited this page Jan 22, 2016 · 4 revisions

Sinatra (and others)

Best Practices

Avoid Rack Handlers

org.jruby.rack.RackInitializationException: Server handler (trinidad,puma,reel,HTTP,webrick) not found.
	from /opt/server/tomcat-8.0.30/webapps/sinatra/WEB-INF/gems/gems/sinatra-1.4.6/lib/sinatra/base.rb:1781:in `detect_rack_handler'
	from /opt/server/tomcat-8.0.30/webapps/sinatra/WEB-INF/gems/gems/sinatra-1.4.6/lib/sinatra/base.rb:1437:in `run!'
    ...
Caused by: org.jruby.exceptions.RaiseException: (RuntimeError) Server handler (trinidad,puma,reel,HTTP,webrick) not found.

There's no need to use handlers - JRuby-Rack does its own "rackup" boot process.

# config.ru
require_relative 'sample/app'
# Sample::App < Sinatra::Base

# ** avoid Sample::App.run! instead: **
run Sample::App

LOAD_PATH

org.jruby.rack.RackInitializationException: no such file to load -- ...

Do not assume a lib (or any other folder) being on the $LOAD_PATH - make sure its properly added or use require_relative or absolute require File.expand_path ....

# config.ru
require './lib/myapp.rb'

# lib/myapp.rb
require 'myapp/helpers' # won't work
require_relative 'myapp/helpers' # or
# $LOAD_PATH << File.expand_path('lib')
Clone this wiki locally