How do you route [OPTIONS] in Rails?

血红的双手。 提交于 2019-12-04 23:07:14
match '/users' => "users#options", via: :options

would also be a possible route if placed before the other routes.

If you don't want to create two additional routes for /users and for /users/id you can do this:

match 'users(/:id)' => 'users#options', via: [:options]

In this case, the id become optional, both /users and /users/id will respond to the same route.

The reason that I could not route the request, was that my match did not have the user id in it. I added the line:

match '/users/:id', :controller => 'users', :action => 'options', :constraints => {:method => 'OPTIONS'}

and now I can route all of my GET request.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!