rubyonrailsin

A Ruby and Rails talk

Monday, March 29, 2010


[Rails] Rails3, Datamapper and select

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

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?

Thanks in advance,

Sylvain

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive