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,但找不到搜索这个的好方法,因为 Google 不喜欢下划线。build_*作为前缀有什么作用?它是否为您附加的任何模型创建了初始化程序?
build_*
它与协会有关。您可以在子类的对象上使用它来构建父关联。你不能反过来使用它。
class Puppy belong_to :dog attr_accessor :name end class Dog has_many :puppies attr_accessor :name end p = Puppy.new(name: "baby") p.build_dog(name: "John)