# Rails3, Datamapper and select

**URL:** <https://www.ruby-forum.com/t/rails3-datamapper-and-select/185972>\
**Category:** Rails\
**Created:** [March 29, 2010, 10:39pm UTC](https://www.ruby-forum.com/t/rails3-datamapper-and-select/185972 "2010-03-29T22:39:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sylvain](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ba0ec/32.png) [@Sylvain](https://www.ruby-forum.com/u/Sylvain)\
**Post date:** [March 29, 2010, 10:39pm UTC](https://www.ruby-forum.com/t/rails3-datamapper-and-select/185972/1 "2010-03-29T22:39:09Z")

</div>

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
