当Passbook在iOS6上向我的服务器发送HTTP DELETE路由时,我得到"No route matches"
配置/路线。Rb,路由看起来像:
delete "/v1/devices/:device_id/registrations/:pass_type_id/:serial_number" => "registrations#destroy"
,当我运行"rake routes"时,我可以看到路由在那里:
DELETE /v1/devices/:device_id/registrations/:pass_type_id/:serial_number(.:format) {:controller=>"registrations", :action=>"destroy"}
,但是当路由以
的形式进入Rails 3.0.3开发服务器时Started DELETE "/v1/devices/515a5c955dcdd66f558e1b4041392bf3/registrations/pass.com.myserver.FreeDrink/11" for 192.168.0.22 at 2012-12-23 15:03:25 -0500
rails服务器说:
ActionController::RoutingError (No route matches "/v1/devices/515a5c955dcdd66f558e1b4041392bf3/registrations/pass.com.myserver.FreeDrink/11"):
actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:53:in `call'
railties (3.0.3) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.4) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.4) lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.4) lib/rack/lock.rb:11:in `call'
actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.3) lib/rails/application.rb:168:in `call'
railties (3.0.3) lib/rails/application.rb:77:in `method_missing'
railties (3.0.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.4) lib/rack/content_length.rb:13:in `call'
rack (1.2.4) lib/rack/handler/webrick.rb:52:in `service'
/home/user/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/home/user/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/home/user/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
所有其他路由,使用HTTP GET和POST工作良好。这是我唯一遇到麻烦的路线。我知道有些浏览器不发送HTTP DELETE,只有HTTP GET和HTTP POST, rails在头中放置一些东西来指示请求是删除,但它是发送HTTP DELETE请求的Passbook,所以我不知道这是否与问题有关。
我还在config/routes中尝试了其他风格的路由。例如:
match "/v1/devices/:device_id/registrations/:pass_type_id/:serial_number" => "registrations#destroy",:via =>:delete
,我也试过使用其他控制器。
有谁知道为什么当请求是HTTP DELETE时Rails说"没有路由匹配"?
我终于通过使用这篇文章中的路由获得了删除路由的工作
delete "/v1/devices/:device_id/registrations/:pass_type_id/:serial_number" => "users#delete_pass", :constraints => { :pass_type_id => /[^/]+/ }
,其中添加了约束:
:constraints => { :pass_type_id => /[^/]+/ }