How to map a custom rack hander in a rails 2.3 application (dav4rack specifically)?
I am trying to use dav4rack in my rails 2.3.8 application. I am creating a custom config.ru file to load rails, and am using Passenger. The standard rails config.ru file loads just fine:
require "config/environment"
use Rails::Rack::LogTailer
use Rails::Rack::Static
run ActionController::Dispatcher.new
But, when I add the mapping for the webdav resource, I get an exception when I run rackup.
# Rails.root/config.ru
require "config/environment"
require 'dav4rack'
use Rails::Rack::LogTailer
use Rails::Rack::Static
开发者_JAVA技巧map "/webdav/" do
run DAV4Rack::Handler.new(:root => "/path/to/app/public")
end
run ActionController::Dispatcher.new
The exception is:
/home/buffy/.rvm/gems/ruby-1.8.7-p302/gems/rack-1.1.0/lib/rack/builder.rb:73:in `to_app': undefined method `call' for #<Hash:0x7f5101b000f0> (NoMethodError)
from /home/buffy/.rvm/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `inject'
from /home/buffy/.rvm/gems/ruby-1.8.7-p302/gems/rack-1.1.0/lib/rack/builder.rb:73:in `each'
from /home/buffy/.rvm/gems/ruby-1.8.7-p302/gems/rack-1.1.0/lib/rack/builder.rb:73:in `inject'
from /home/buffy/.rvm/gems/ruby-1.8.7-p302/gems/rack-1.1.0/lib/rack/builder.rb:73:in `to_app'
from config.ru:1
I'm pretty new to rack configuration and running rails 3 isn't an option for this application right now. Any ideas why config.ru doesn't like the map call?
UPDATED: I figured it out using railties/lib/commands/server.rb as an example. My config.ru file now looks like this:
# Rails.root/config.ru
require 'config/environment'
require 'dav4rack'
use Rails::Rack::LogTailer
map '/' do
use Rails::Rack::Static
run ActionController::Dispatcher.new
end
map '/webdav/' do
use Rack::CommonLogger
run DAV4Rack::Handler.new(:root => '/pat/to/app')
end
Which runs successfully with rackup.
精彩评论