微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails-3 – 如何在Rails中路由[OPTIONS]?

我在Rails中做一个REST服务.这是我的路线.
resources :users
  match '/users',:controller => 'users',:action => 'options',:constraints => {:method => 'OPTIONS'}

我能够[GET]我的用户.我想更新我的用户,我收到一个错误

ActionController::RoutingError (No route matches [OPTIONS] "/users/1"):

当我运行耙子路线这里是我给的路线:

users GET    /users(.:format)          users#index
          POST   /users(.:format)          users#create
 new_user GET    /users/new(.:format)      users#new
edit_user GET    /users/:id/edit(.:format) users#edit
     user GET    /users/:id(.:format)      users#show
          PUT    /users/:id(.:format)      users#update
          DELETE /users/:id(.:format)      users#destroy
                 /users(.:format)          users#options {:method=>"OPTIONS"}

有人可以告诉我如何修复我的路由,所以我可以做任何形式的REST调用?谢谢.

解决方法

match '/users' => "users#options",via: :options

如果放在其他路线之前,也可能是一条可能的路线.

原文地址:https://www.jb51.cc/ruby/272908.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐