Forum: Rails France Rails3 et les select

Posted by Sylvain (Guest)
on 2010-03-25 12:26
(Received via mailing list)
Bonjour à tous,
je teste rails3 avec datamapper avec un projet simple.

J'ai deux 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

que j'ai créé en utilisant rails generate scaffold.

j'ai donc dans le répertoire "vue" 5 templates erb, dont un qui est
utilisé pour "new" et "edit" (_form).
j'ai ajouté dans _form du client un select pour choisir la société
auquel il appartient :

<%= 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 %>


A la création, tout se passe bien (le client est créé, on le voit dans
l'index...).
Par contre à l'édition, j'ai ce problème :

 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 %>

Une idée pourquoi ça marche avec un client "vide" et pas avec un
client déjà existant ?

merci d'avance !

Sylvain

--
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de 
Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse 
railsfrance@googlegroups.com
Pour résilier votre abonnement envoyez un e-mail à l'adresse 
railsfrance-unsubscribe@googlegroups.com

To unsubscribe from this group, send email to 
railsfrance+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.