0
私は3種類のシンプルなモデル - Car
,Details
、Details2
を持っています。 Car
がDetails
、Details
が多く、Details2
が多い。私はのような関連付けを設定しますMySQLとのActiveRecordでMongoidとの関連
:私は車のリストを持っているビューで、
class Car
has_many :details
end
class Detail
belongs_to :car
end
は、私が持っている:
<% @cars.each do |car| -%>
<%=car.details.count%> #uninitialized constant Details
<% end %>
EDIT2: これを私が持っているものは車テーブル:
db.cars.find()
{ "_id" : ObjectId("4efe69716f85ce447a000054"), "name" : "bmw", "descr" : "asasgasga as gas gas ", "updated_at" : "Sat Dec 31 2011 02:46:25 GMT+0100 (CET)", "created_at" : "Sat Dec 31 2011 02:46:25 GMT+0100 (CET)" }
の
と詳細:
db.details.find()
{ "_id" : ObjectId("4f01106d6f85ce6b850000b8"), "car_id" : ObjectId("4efe69716f85ce447a000054"), "name" : "20120102030325", "descr" : "dsg", "updated_at" : "Mon Jan 02 2012 03:03:25 GMT+0100 (CET)", "created_at" : "Mon Jan 02 2012 03:03:25 GMT+0100 (CET)" }
そして、私はこれだけのアクションを持っている CarsController 中:私は何をすべきかすべてです
def index
@cars = Car.all
end
。
はい、申し訳ありませんが、私のせいです。もう寝る必要がある。しかし、今では 'car.details.count'を試してみると、' '初期化されていない定数' 'を得るでしょう。 – user984621
あなたが持っているコードを投稿してください。 –
オリジナルの投稿を更新しました。 – user984621