Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果找到记录,Rails find_or_create_by() 是否也会更新记录属性。如果没有,有没有简单的方法来查找或创建记录,如果记录已经存在;更新记录属性
听起来你想要做 a 的东西create_or_update_by, 这可能是这两个步骤:
create_or_update_by
my_app_class = ClassName.find_or_initialize_by_name(last_name, first_name).update_attributes ({ :last_name => self.last_name, :first_name => self.first_name, })