Sinatra cannot find views on Ruby 1.9.2-p0

I'm quite new to Ruby language (up to now I developed in Groovy + Grails) but since I was curious about it I wanted to try Sinatra on Ruby 1.9.2-p0.

I have a trivial website that is contained in /mywebpage and has 2 files:

# blog.rb
get '/' do
  'Hello World!'
end

get '/impossible' do
  haml :index
end

and

#config.ru
path = File.expand_path "../", __FILE__

$LOAD_PATH << (File.expand_path ".") + "/views"

require 'haml'
require 'sinatra'
require "#{path}/blog"

run Sinatra::Application

then in the same folder I have a /views/ folder that contains index.haml.

I try to run the server with rackup -p8080 but when I try to get /impossible I receive the following error:

Errno::ENOENT at /impossible
No such file or directory - /home/jack/mywebpage/<internal:lib/rubygems/views/index.haml

By searching over internet it seems that this maybe caused by "." not being included in $LOAD_PATH so I tried to add it or add directly views ./views so that actually $LOAD_PATH.inspect gives me correct path: ..., "/home/jack/mywebpage/views"]

But still it doesn't seem to work. Being quite new to the framework and the language I was wondering if I'm doing something wrong. any clues?

5
задан Nakilon 3 February 2017 в 18:42
поделиться