Bundler problem (difference between projects) [SOLVED]

I am slowly learning Ruby as well as Sinatra. Now I would like to have
two different projects on my machine, both using Sinatra, the same
version of Ruby (2.1.2). I have installed Bundler and have separated
vendor/bundle folders inside projects’ folders. I am using .rbenv with
ruby-build plugin.

In the first project I have three files, something like 1) server.rb, 2)
config.ru, 3) Gemfile. It includes basic things needed for running the
very basic project with Sinatra. Bundler worked well as well as
everything at all. It is possible to use “bundle exec rackup -p ‘port’”,
WEBrick is started, everything smooth. I have not tested another server
yet.

The problem is with the second project. There I have even more basic
setting. Later I wish I was able to run it via Thin server.

  1. server.rb
    #!/usr/bin/ruby
    require ‘sinatra’
    get ‘/’ do
    “Hello, world!”
    end

  2. gems included
    rack-protection-1.5.3
    rack-1.5.2
    sinatra-1.4.5
    tilt-1.4.1

Than it says:

ruby server.rb
/home/user/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in
require': cannot load such file -- sinatra (LoadError) from /home/user/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require’
from server.rb:3:in `’

Of course I had used rbenv rehash for sure.

When I am trying to run the whole thing after properly installing Thin
via Bundler as bundle exec thin start, it says:

No adapter found for /home/user/git/sinatra-training found for
/home/honza/git/sinatra-training-oreilly

Bundler says everything is ok. I have no idea where could be the
problem…

Any help appreciated!

Ok, for now really solved. It seems when using Bundler and Sinatra
together, it is needed to provide a config.ru file and initialize the
class:

config.ru file:

$: << File.dirname(FILE)
require ‘server.rb’

run Server.new

server.rb file:

#!/usr/bin/ruby

require ‘sinatra/base’

class Server < Sinatra::Base
get ‘/’ do
“Hello, world!”
end
end

Than it is possible to run that with bundle exec thin start… working
smoothly.

I have no idea if it is possible to run that without this, like it was
intended in my Sinatra book by O’Reilly (Sinatra Up and Running). There
they simply run ruby server.rb and it should work but I suppose just
because of the fact they don’t use Bundler and rbenv there. I think my
problem was caused by another configuration.

Honza Hejzl wrote in post #1154854:

I have no idea if it is possible to run that without this, like it was
intended in my Sinatra book by O’Reilly (Sinatra Up and Running). There
they simply run ruby server.rb and it should work but I suppose just
because of the fact they don’t use Bundler and rbenv there. I think my
problem was caused by another configuration.

Have you tried bundle exec ruby server.rb ?

You must not forget to put the line Server.run! at the end of
server.rb file.

If you make the server.rb file executable and add the hashbang entry
like #!/usr/bin/env ruby, you can start the server even by bundle exec ./server.rb .

Will try that in this way, thanks!

It works! Cute, thank you!