私は得ています
未定義のメソッド `Carrots' for # (ln#18 を参照)
以下のフォームで編集しようとすると:
= form_for @harvest do |f|
- if @harvest.errors.any?
#error_explanation
%h2= "#{pluralize(@harvest.errors.count, "error")} prohibited this harvest from being saved:"
%ul
- @harvest.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :created_at
= f.text_field :created_at, :disabled => true
%br
= f.label :photo
= f.text_field :photo
%h2 Crops
- @harvest.harvested_crops.each do |harvested_crop|
= f.label :harvested_crop['crop']
= f.select harvested_crop['crop'], Crop.all.collect {|p| [ p.name, p.id ] }, {:include_blank => ''}
= f.label :harvested_crop['amount']
= f.text_field harvested_crop['amount']
%br
.actions
= f.submit 'Save'
以下のデータを使用します。
{ "_id" : ObjectId("5067846f37bca62bccc3729e"), "user_id" : "5067844637bca62bccc3729c", "photo" : "carrotsnspuds.jpg", "harvested_crops" : [ { "crop" : "Carrots", "amount" : 1112.15 }, { "crop" : "Potatoes", "amount" : 3212.44 } ] }
MongoMapper、Rails、Embedded ドキュメントの関連する Stack Overflow の質問を試しましたが、おそらくこれが EmbeddedDocument ではなくネストされた配列であるため、うまくいきません。私はまだ Formtastic などを使用していません。最初にここで必要な構文を理解したいだけです。