默认情况下,Rails路由的resources
关键字会创建7个操作。
例如resources :foos
:
-----------------------
| Verb | Action |
-----------------------
| GET | index |
| GET | show |
| GET | edit |
| GET | new |
| PUT/PATCH | update |
| POST | create |
| DELETE | destroy |
-----------------------
我们如何在此列表中添加OPTIONS
动词,例如:
--------------------------------
| Verb | Action |
--------------------------------
| ... | ... |
| OPTIONS | member_options |
| OPTIONS | collection_options |
--------------------------------
换句话说,默认情况下,对于每种资源,我们都必须使用以下内容:
match '/foos/', via: :options, controller: 'foos', action: 'collection_options'
match '/foos/:id/', via: :options, controller: 'foos', action: 'member_options', as: :foo
resources :foos
相反,我更喜欢自定义设置才能执行此操作:
resources :foos
答案 0 :(得分:0)
为避免列出OPTIONS动词的每个路径,您可以添加catch all route,例如
match '*path', to: 'application#cors_preflight_check', via: [:options]