Rails Put vs Post

后端 未结 4 1434
自闭症患者
自闭症患者 2021-01-04 06:12

I have been reading up on the difference between put and post requests and I have some related questions as it pertains to rails: I would like to change one specific field i

4条回答
  •  北海茫月
    2021-01-04 06:36

    According to rails convention,

    PUT is used for updating an existing resource

    POST is used for creating a new resource

    In rails 4, PUT has been changed to PATCH to avoid confusion.

    Rails generated routes will look like below by default

        posts GET    /posts(.:format)                            {:action=>"index", :controller=>"posts"}
              POST   /posts(.:format)                            {:action=>"create", :controller=>"posts"}
     new_post GET    /posts/new(.:format)                        {:action=>"new", :controller=>"posts"}
    edit_post GET    /posts/:id/edit(.:format)                   {:action=>"edit", :controller=>"posts"}
         post GET    /posts/:id(.:format)                        {:action=>"show", :controller=>"posts"}
              PUT    /posts/:id(.:format)                        {:action=>"update", :controller=>"posts"}
              DELETE /posts/:id(.:format)                        {:action=>"destroy", :controller=>"posts"}
    

    Notice the action for PUT and POST

提交回复
热议问题