Rails3, Datamapper and select

Hi all,
I’m testing rails3 with Datamapper on a simple project.

I’ve 2 classes :
class Societe
include DataMapper::Resource

property :id, Serial
property :nom, String
property :adresse, Text

has n, :clients
end

class Client
include DataMapper::Resource

property :id, Serial
property :prenom, String
property :nom, String
property :telephone, String
property :courriel, String
property :adresse, Text
property :view_only, Boolean

belongs_to :societe
end

I created them using rails generate scaffold (except belongs/ has of
course).

I’ve then have in the folder “view” 5 erb templates per class, and
especially one (_form) used by “new” and “edit” templates.
In order to select the society, I have added in client’s _form a
select:

<%= form_for(@client) do |f| %>
<%= f.error_messages %>

<%= f.label :societe %>
<%= f.select(:societe_id, @societes.map{|s| [s.nom, s.id]}) %>
<%= f.submit %>
<% end %>

In creation mode, everything is allright and the customer is created
with the link to its society
But when I edit, I have the following error:

Showing /home/…/app/views/clients/_form.html.erb where line #30
raised:

undefined method `societe_id’ for #Client:0xa51833c

Extracted source (around line #30):

27:
28:


29: <%= f.label :societe %>

30: <%= f.select(:societe_id, @societes.map{|s| [s.nom, s.id]}) %>
31:

32:

33: <%= f.submit %>

Any idea why it’s working with empty “client” and not with existing
one?

Thanks in advance,

Sylvain

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs