我有一个Books控制器,我需要为API webservice配置restful路由。我需要设置以下url的路由
books/book_id/search
books/book_id/delete
books/book_id/next
我该怎么做
答案 0 :(得分:1)
假设您要为您的GET
和search
API使用HTTP方法next
,并为您的DELETE
API使用HTTP方法delete
,我会设置这样的路线(假设你有一个books
控制器,并且各自的动作):
get 'books/:book_id/search', to: 'books#search'
delete 'books/:book_id/delete', to: 'books#delete'
get 'books/:book_id/next', to: 'books#next'
仅供参考,这是将non-resourceful routing与dynamic segments, static segments和defaulting组合使用到名为books
的控制器。