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 %>
...
<div class="field">
<%= f.label :societe %><br />
<%= f.select(:societe_id, @societes.map{|s| [s.nom, s.id]}) %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% 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: </div>
28: <div class="field">
29: <%= f.label :societe %><br />
30: <%= f.select(:societe_id, @societes.map{|s| [s.nom, s.id]}) %>
31: </div>
32: <div class="actions">
33: <%= f.submit %>
Any idea why it's working with empty "client" and not with existing
one?
Digging a little bit the problem, it seems it's because the select in
base doesn't take the societe_id (which is "magically" retrieved I
think):
SELECT "id", "prenom", "nom", "telephone", "courriel", "view_only"
FROM "clients" WHERE "id" = 1 ORDER BY "id" LIMIT 1
Thanks in advance,
Sylvain
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.