Sinatra via rackup does not like inline templates

rackup, sinatra, templates

Solution

From the docs:

Inline templates defined in the source file that requires sinatra are automatically loaded. Call `enable :inline_templates` explicitly if you have inline templates in other source files.

In this case, when you use `rackup` it is your `config.ru` that calls `require 'sinatra'`, and Sinatra is looking in that file for any templates, and doesn’t find any. When you run your app file directly Sinatra searches `tubemp.rb` for the templates, and finds them.

To fix it, add

enable :inline_templates

to your `tubemp.rb` file (and any other source files that have inline templates).

Problem

When calling sinatra itself, `$ ruby tubemp.rb` works. But via `rackup` it does not. The application, somehow cannot find the inline templates. ``` #config.ru require 'rubygems' require 'sinatra' set :environment, ENV['RACK_ENV'].to_sym disable :run, :reload require './tubemp.rb' run Sinatra::Application ``` The error being returned is: ``` No such file or directory - /home/ber/Documenten/ET_tubemp/code/views/index.erb: ``` Relevant part from `tubemp.rb` ``` get '/' do #... erb :index end __END__ @@ layout <html> ... <%= yield %> @@ index Welcome! ``` Somehow, via rackup, it expects the views to live in actual view-files. I guess the rackup cannot handle the `__END__` token when including or so. How should I deal with this, other then moving my templates into template files?

Original source