在rails中配置路由

时间:2014-04-17 21:44:23

标签: ruby-on-rails-3 routes

我有一个Books控制器,我需要为API webservice配置restful路由。我需要设置以下url的路由

books/book_id/search
books/book_id/delete
books/book_id/next

我该怎么做

1 个答案:

答案 0 :(得分:1)

假设您要为您的GETsearch 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 routingdynamic segments, static segmentsdefaulting组合使用到名为books的控制器。