ubuseral
ubuseral

Reputation: 427

Rails: form field

I have one city with many people.

I want to add a select-field in my city form to add people:

<%= form_for(@city) do |f| %>
<p>
  <%= f.label city.people.id, "Person" %><br />
  <%= f.select  city.people.id,
         Person.find(:all).collect{|d| [d.person_name,d.id]},
         :prompt => "Please choose" %>
</p>
<% end %>

Rails said: undefinied varialbe city. I implemented in city has:many and in person belongs_to.

Whats wrong with my code snippet?

Upvotes: 0

Views: 46

Answers (1)

Kaeros
Kaeros

Reputation: 1138

You have to use the instance variable @city, don't forget the @ symbol.

Also, @city.people is a collection of type Person, so @city.people.id does not work.

Upvotes: 1

Related Questions