Rails new vs create

前端 未结 4 498
终归单人心
终归单人心 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条回答
  •  -上瘾入骨i
    2020-11-28 18:24

    New instantiates a new Model instance, but it is not saved until the save method is called.

    Create does the same as new, but also saves it to the database.

    Sometimes you want to do stuff before saving something to the database, sometimes you just want to create and save it straight away.

提交回复
热议问题