0

初心者の質問はこちら。ネストされたフォームに mongoid、rails 3.2、nested_form を使用しています。

私はそのProfileモデルを持っていembeds_many :servicesます。ネストされたフォームを使用しており、データベースに正常に保存できました。ただし、埋め込まれたドキュメントを自分のページに表示する方法がわかりません。これは、パズルの最も簡単なピースのようです。以下は私のデータベースがどのように見えるかです:

{ "_id" : ObjectId( "507d6fc757299e4a0c000002" ),
  "biz_name" : "Shop Co",
  "services" : [ 
    { "_id" : ObjectId( "508c066a57299ef138000008" ),
      "s_and_p_service_description" : "what a great pie",
      "s_and_p_service_title" : "Pie" }, 
    { "_id" : ObjectId( "508c079357299ef138000009" ),
      "s_and_p_service_title" : "Fruit",
      "s_and_p_service_description" : "what a great fruit" } ],
  "updated_at" : Date( 1351354259379 ),
  "user_id" : ObjectId( "507d6fc757299e4a0c000001" ) 
}

私はこのようなものがそれを行うだろうと思った:

<% @profile.services.each do |service| %>                           
    <%= @profile.services.s_and_p_service_title %>
<% end %>

しかし、私は次のエラーが発生します:

undefined method `s_and_p_service_title' for #<Array:0x007fa22a643c18>

私は何を間違っていますか?

4

1 に答える 1

1

そこに少しコピー/貼り付けしすぎたと思います。これを試して:

<% @profile.services.each do |service| %>                           
    <%= service.s_and_p_service_title %>
<% end %>
于 2012-10-27T19:22:44.350 に答える