#901 ✓not-applicable
yves.senn (at gmail)

fields_for in Rails not working with one-to-many associations

Reported by yves.senn (at gmail) | June 13th, 2009 @ 05:49 AM

The ActionView::Helpers::FormHelper#fields_for method in Rails 2.3 allows you to create forms with nested models. This does not work with DataMapper and the one-to-many association. It seems, that it always uses one-to-one associations. The example below illustrated the problem:


class Artist
  include DataMapper::Resource
  property :id, Serial

  has n, :profiles

class Profile
  include DataMapper::Resource
  property :id, Integer, :serial => true
  property :data, String
  property :adapter, String

  belongs_to :artist


<% form.fields_for :profiles do |p| %>    
  <p><label for=""><%= p.object.adapter %></label>
    <%= p.text_field :data %>
<% end %>

Generated field:

<input id="artist_profiles_data" name="artist[profiles][data]" size="30" type="text" />

Expected field:

<input id="artist_profiles_0_data" name="artist[profiles][0][data]" size="30" type="text" />

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »