Two Models Country and Bank. The below form is used for insert and edit
page works fine . f.collection_select works fine for edit page but
throws
error for insert page. I think error it is trying to populate the
selected
value in the combo box but country id is not available. Can you help me
fixing the issue? What is prompt used for?
Error
undefined method `map’ for nil:NilClass
Extracted source (around line #23):
20: <%= f.label :country_id %>
21:
22:
23: <%= f.collection_select :country_id, @countries, :id, :name,
:prompt => “Test” %>
24:
25:
26: <%= f.submit %>
class Bank < ActiveRecord::Base
attr_accessible :name,:country_id
belongs_to :country
validates :name, :presence => true
validates_presence_of :country
end
class Country < ActiveRecord::Base
attr_accessible :name
end
Form
<%= form_for(@bank) do |f| %>
<% if @bank.errors.any? %>
<%= pluralize(@bank.errors.count, “error”) %> prohibited this
bank from being saved:
<ul>
<% @bank.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.text_field :name %>
<%= f.collection_select :country_id, @countries, :id, :name,
:prompt
=> “Test” %>