Hi there, it’s kind of a weird problem. I have a Person model and
Person controller. In the new method in my controller I try to retrieve
a collection of nationalities. The nationalities are stored in a
different table. So retrieving those should be like:
def new
@person = Person.new
@person.name = Name.new
@person.birthday = Date.today
@person.nationality = Nationality.new
nationalities = Nationality.find( :all )
end
Unfortunately when Rails try to access the array in the new.rhtml it’s
nil. Here, I create a selection list, as follows:
<% form_for :gender do |form| %> <%= form.select( :gender, @genders ) %> <% end %>
The weird thing happens when I retrieve the array inside new.rhtml.
It’s working here.
<% form_for :nationality do |form| %> <%= @nationalities = Nationality.find( :all ) form.select( :nationality, @nationalities ) %> <% end %>
As stated in the new Web D. book those code should normally
reside in the controller.
Am I missing something?
Thanks ahead,
Christian