Rails first_or_create ActiveRecord method

前端 未结 4 451
你的背包
你的背包 2021-02-05 01:53

What does the first_or_create / first_or_create! method do in Rails?

According to the documentation, the method \"has no description\"

4条回答
  •  独厮守ぢ
    2021-02-05 02:54

    If you check the source, you will see that they are almost identical. The only difference is that the first one calls the "create" method and the other one "create!". This means that the second one will raise an exception, if the creation is not successful.

提交回复
热议问题