我在Rails應用程序中有以下模型。Rails從關係中訪問多態數據
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end
class Client < ActiveRecord::Base
has_one :address, :as => :addressable, dependent: :destroy
accepts_nested_attributes_for :address, :allow_destroy => true
has_many :invoices
end
class Invoice < ActiveRecord::Base
belongs_to :client
end
雖然我能夠使用
@invoice.client.name
檢索客戶名,我不能夠檢索以類似方式的地址信息。
如何檢索發票視圖中的地址屬性?
@ invoice.client.address –