0
我想使用Mongoid爲Rails 3中的模型加入URL。問題是我想在slug中使用的字段位於子模型中。我使用mongoid-slug寶石找到解決這一點,我的嘗試,到目前爲止是這樣的:如何使用來自子模型的字段拼版父模型?
class Building
references_one :address
def to_param
address.to_param
end
end
class Address
referenced_in :building
field :houseno
field :street
slug :houseno, :street
end
雖然這讓我通過調用building_path(building)
形成正確的網址,頁面不包含正確的值。錯誤消息抱怨對象ID不正確,我不確定如何讓Rails通過to_param來偵聽和查找記錄。