Newbie question here. I am using mongoid, rails 3.2 and nested_form for my nested forms.
I have a Profile model that embeds_many :services. I’m using a nested form and have been able to successfully save it to my db. However, I can’t figuer out how to display the embeded documents on my page. This seems like the easiest piece of the puzzle. Below is what my db looks like:
{ "_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" )
}
I thought something like this would have done it in:
<% @profile.services.each do |service| %>
<%= @profile.services.s_and_p_service_title %>
<% end %>
but I get the follow error:
undefined method `s_and_p_service_title' for #<Array:0x007fa22a643c18>
What am I doing wrong?
I think you copy/pasted a little bit too much there. Try this: