Rails new vs create

前端 未结 4 505
终归单人心
终归单人心 2020-11-28 17:56

Why is there a need to define a new method in RESTful controller, follow it up with a create method?

Google search didn\'t provide me the answer I was looking for. I

4条回答
  •  甜味超标
    2020-11-28 18:17

    Within Rails' implementation of REST new and create are treated differently.

    An HTTP GET to /resources/new is intended to render a form suitable for creating a new resource, which it does by calling the new action within the controller, which creates a new unsaved record and renders the form.

    An HTTP POST to /resources takes the record created as part of the new action and passes it to the create action within the controller, which then attempts to save it to the database.

提交回复
热议问题