3

Doing the getting started of Sinatra. I get this error:

./sinatra.rb:5: undefined method `get' for main:Object (NoMethodError)
        from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
        from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
        from sinatra.rb:3

Googling on these errors returns ruby LoadError: cannot load such file which I don't see how that relates to Sinatra.

Not sure what other info I need to share to make my question clearer. So just tell me what other commands I should run to make the question clear.

UPDATE: Actual code

# sinatra.rb
require 'rubygems'
require 'sinatra'

get '/' do
        'hey girl'
end
Community
  • 1
  • 1
isomorphismes
  • 8,233
  • 9
  • 59
  • 70

1 Answers1

5

The problem here is due to you naming your file sinatra.rb. When you run that file, the first thing it does is require 'sinatra', and since the current directory is on the load path in Ruby 1.8.7, it tries to load itself. It then gets to the call to get '/' do ..., but since the real Sinatra hasn’t been loaded this results in the error.

The fix is to rename your file to something other than sinatra.rb, you could use myapp.rb as suggested in page you linked to.

matt
  • 78,533
  • 8
  • 163
  • 197