2012-03-12 21 views

回答

1

REST(由Rails使用)對資源進行操作。具體來說,它使用HTTP動詞(GET,POST,PUT,DELETE)來操作資源。

假設你有一個電影模型。你可能有一個電影資源這將定義以下路線:

GET '/movies' - Gets a list of movies 
GET '/movies/new' - Gets the form to create a new movie 
POST '/movies' - Creates a new movie 
GET '/movies/:id' - Gets the details about the movie with :id 
GET '/movies/:id/edit' - Edits the movie with :id 
DELETE '/movies/:id' - Deletes the movie with :id 
PUT '/movies/:id' - Updates the movie with :id 

,另一方面排序是提供導軌和關於請求的其他信息的一種方式。因此,如果您要在模型或資源上執行CRUD操作,您應該使用RESTful路由(as described by the railsguide),否則您可能需要一個參數,或者您可以考慮使用JavaScript對數據客戶端進行排序!

請注意,沒有任何東西阻止您實施像'/movies/sort/title'這樣的路線,它只是不是一條REST風格的路線,並且需要您的routes.rb文件中的自定義路線。只要閱讀我上面鏈接的完整故事的railsguide。