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

后端 未结 6 627
有刺的猬
有刺的猬 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:37

    I won't go on to explain more about REST since I think that has been answered in this question, however I will talk a little bit about the default route.

    My main problem with the default route is that if you have multiple sites using the same Rails app it can look horrible.

    For example there may be controllers that you don't want people to be able to see on one app:

    http://example1.somesite.com/example_2/foo/bar/1
    

    compare this to

    /:controller/:action/:id
    

    This would go to the controller example_2/foo, action bar and id 1

    I consider this to be the main flaw of Rails' default route and this is something that RESTful routes (with subdomain extensions) or only named routes (map.connect 'foo' ... ) can fix.

提交回复
热议问题