How to initialize an ActiveRecord with values in Rails?

前端 未结 5 1716
情话喂你
情话喂你 2020-12-17 08:35

In plain java I\'d use:

public User(String name, String email) {
  this.name = name;
  this.email = f(email);
  this.admin = false;
}

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-17 09:08

    According to Rails Guides the best way to do this is with the after_initialize. Because with the initialize we have to declare the super, so it is best to use the callback.

提交回复
热议问题