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?
Sinatra::Base is the Sinatra without delegation. Consider the following code with delegation: # app.rb require 'sinatra' get '/' do render :template end.
Sinatra is a free and open source software web application library and domain-specific language written in Ruby. It is an alternative to other Ruby web application frameworks such as Ruby on Rails, Merb, Nitro, and Camping. It is dependent on the Rack web server interface.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With