Differences in rails between new + save and create

前端 未结 4 1623
抹茶落季
抹茶落季 2020-12-07 16:17

I\'m new to rails and I don\'t understand the differences between the use of new+save methods and the create method.

def create
    @item = Item.new(params[:         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 16:55

    when you use, rails actually is creating the records but didn't save it, so in the process you can also assign smth

    @item = Item.new(params[:item])
    

    but when you use:

    if Item.create(params[:item])
    .....
    

    it will immediately create and save

    you can check it with rails c

提交回复
热议问题