Why do I get NameError when I run a rack app with "rackup"?
I'm having trouble running a rack app using rackup
.
This is my config.ru:
$:.unshift "#{File.dirname(__FILE__)}/lib/"
require 'blogrite'
run Blogrite::Server.new(:with => :test)
Calling rackup config.ru
throws:
[~/Code/blogrite master] rackup config.ru
/Users/josemota/Code/blogrite/lib/blogrite/server.rb:2:in `<module:Blogrite>': uninitialized constant Blogrite::Server (NameError)
from /Users/josemota/Code/blogrite/lib/blogrite/server.rb:1:in `<top (required)>'
from /Users/josemota/Code/blogrite/config.ru:5:in `block in <main>'
...
You can check the 开发者_JS百科full project in Github. I do not understand the reason I get NameError
.
I have found the reason for this error to come up. The NameError shown is fired from the module, which won't recognize the paths correctly.
@Dogbert correctly pointed out that autoload was probably not working. According to Dave Barker in his post, the class that autoloads must include the current path in $:
/ $LOAD_PATH
. I did that and now it works.
The resulting commit is now available. Thanks @Dogbert for pointing the autoload issue in the first place!
精彩评论