我想知道在Rails中使用關聯時New和Create方法的源(即定義類或模塊)是什麼。使用關聯時新建和創建方法的Rails ActiveRecord的來源
例如,導軌導向件的關聯部分提供了這種情況:
class Customer < ActiveRecord::Base
has_many :orders, :dependent => :destroy
end
class Order < ActiveRecord::Base
belongs_to :customer
end
然後在控制檯輸入該命令:
@order = @customer.orders.create(:order_date => Time.now)
(鏈接到導軌指南部分:http://guides.rubyonrails.org/association_basics.html)
但是當我輸入這個:
@customer.orders.method(:create)
我得到的錯誤:
undefined method `create' for class `Array'
訂單類中是否有創建方法? – 2013-05-13 06:52:38
選中此項:http://stackoverflow.com/a/10430216/1322562 – jdoe 2013-05-13 06:57:06