Why do I need to work harder to make my Rails application fit into a RESTful architecture?

后端 未结 6 610
有刺的猬
有刺的猬 2020-12-23 11:44

I started a Rails project recently and decided to use RESTful controllers. I created controllers for my key entities (such as Country) and added index, ne

6条回答
  •  礼貌的吻别
    2020-12-23 12:40

    REST does not specify that you can't have additional views. No real world application is going to be able use only the supplied actions; this is why you can add your own actions.

    REST is about being able to make stateless calls to the server. Your search action is stateless each time as the data so far is supplied back, correct? Your alternate display action is also stateless, just a different view.

    As to if they should be manual routes or a new controller, that depends on how distinct the activity is. Your alternate view, if it provides a full set of CRUD (create, read, update, delete) operations would do well to be in a new controller. If you only have an alternate view to the data, I would just add an alternate view action.

    In other words, it doesn't sound like your application is failing to be RESTful, it is more an issue of realizing that the automatically generated feature set is a starting point, not a conclusion.

提交回复
热议问题