[Nitro] Controller not being picked up by dispatcher
Marcus Edwards
redentis at gmail.com
Tue Aug 2 04:36:39 EDT 2005
All,
Please can someone help with the follow (extraordinarily) simple
problem: my controller isn't being recognised, what's wrong?
---8<--- run.rb
#!/usr/bin/env ruby
require 'nitro'
require 'src/controller'
STDERR.sync = true if not STDERR.sync
# $DBG = true
include Nitro
Nitro.run do |conf|
conf.dispatcher = Dispatcher.new(
'/book' => BookController
)
conf.set(
:name => 'Pendleton House Library',
:host => '127.0.0.1',
:port => 9999
)
end
---8<---
---8<--- controller.rb
require 'nitro/controller'
include Nitro
class BookController < Controller
# should use the default index method
def search
puts "BookController.search"
end
end
---8<---
---8<--- index.xhtml
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<a href="/book/search">Search</a>
</body>
</html>
---8<---
The output I get on the console is:
---8<--- (stdout)
$ ruby run.rb
==> Listening at 127.0.0.1:9999. (debug mode)
[2005-08-02 08:59:30] INFO WEBrick 1.3.1
[2005-08-02 08:59:30] INFO ruby 1.8.2 (2004-12-25) [i386-cygwin]
[2005-08-02 08:59:30] INFO WEBrick::HTTPServer#start: pid=4500 port=9999
DEBUG: Rendering '/'.
DEBUG: Compiling action 'Nitro::SimpleController#index'
DEBUG: Compiling template 'Nitro::SimpleController: public/index.xhtml'
DEBUG: Rendering '/book/search'.
DEBUG: Compiling action 'Nitro::SimpleController#book'
ERROR: Error while handling '/book/search'.
ERROR: undefined method `book_action' for #<Nitro::SimpleController:0x108fbe28>
/usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro/controller.rb:165:in `metho
d_missing'
/usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro/render.rb:111:in `send'
/usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro/render.rb:111:in `render'
/usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro/adapter/webrick.rb:120:in `
do_GET'
/usr/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35:in `__send__'
/usr/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:155:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:144:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:144:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:94:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:89:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:89:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:79:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:79:in `start'
/usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro/adapter/webrick.rb:42:in `s
tart'
/usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro/server/runner.rb:278:in `in
voke_server'
/usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro/server/runner.rb:246:in `in
voke'
/usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro/server.rb:107:in `run'
/usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro.rb:74:in `run'
run.rb:24
LOGGED FROM: /usr/lib/ruby/gems/1.8/gems/nitro-0.21.2/lib/nitro/render.rb:160:
in `log_error'
DEBUG: Rendering '/error'.
DEBUG: Compiling action 'Nitro::SimpleController#error'
DEBUG: Compiling template 'Nitro::SimpleController: public/error.xhtml'
---8<---
My guess is that there is something wrong with the dispatcher
configuration but I can't work out what it is. I haven't defined a
dispatcher for '/' as I was expecting that to pick up
/public/index.xhtml and render that. As it is, it looks like attempts
to render '/book/search' are being dispatched to the default
SimpleController and not my BookController.
Any help much appreciated.
Thanks,
Marcus
More information about the Nitro-general
mailing list