Sinatra can't find views on Ruby 1.9.2-p0

I am new to Ruby (so far I have developed Groovy + Grails), but since I was interested, I wanted to try Sinatra on Ruby 1.9.2-p0.

I have a trivial website that is contained in /mywebpageand 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 folder /views/containing index.haml.

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

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

When searching over the Internet, it seems that this may be caused by "." not being included in $LOAD_PATH, so I tried adding it or adding direct views ./viewsso that it actually $LOAD_PATH.inspectgave me the correct path:..., "/home/jack/mywebpage/views"]

- . , , - . ?

+5
5

Sinatra Ruby 1.9.2 "", .

set :views, File.dirname(__FILE__) + "/views"

, Ruby Kernel#__dir__() , File.dirname(__FILE__).

+12
+3

this. , , , . , , Sinatra ( , 1.9.2).

#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'

enable :run

get '/' do
  "Hello, world!"
end

: , Sinatra 1.9.2. Sinatra 1.9.2. ( ), . , , . , , .

+1
gem install sinatra --pre
+1

Sinatra, . rvm synatra Ruby 1.8.7, , , .

, Ruby, , , rvm, . RVM Mac Ruby . Ruby . ~/.rvm, , .

http://rvm.beginrescueend.com/

Sinatra , , - , , :

http://github.com/sinatra/sinatra/issues/#issue/50

, Sinatra, № 50, . , , , :

gem env "GEM PATHS". . , № 50, base.rb. - ...gems/ruby-1.9.2-p0/gems/sinatra-1.0/lib/sinatra/base.rb.

:

    /<internal:/, # ruby 1.9.2-p0 hacks
1020.

, .

0

All Articles