New To Rails

I am new to Ruby On Rails.

I have scaffolded a few screens for a website’s administration pages.

For example, right now I have (etc., etc.):

admin/companies
admin/regions
admin/countries

I am going back and editing the scaffolded screens.

I need to know how to add a dropdown list to the
admin\regions_form.html.erb page that would show the countries I have
added using admin/countries/new.

On Sep 25, 2012, at 6:44 PM, DONEIN NET wrote:

I am going back and editing the scaffolded screens.

I need to know how to add a dropdown list to the
admin\regions_form.html.erb page that would show the countries I have
added using admin/countries/new.

If your region belongs_to country, then you could do something like this
(inside a form_for for the region):

<%= f.collection_select :country_id, Country.order(:name), :id, :name %>

Walter

Walter D. wrote in post #1077557:

On Sep 25, 2012, at 6:44 PM, DONEIN NET wrote:

I am going back and editing the scaffolded screens.

I need to know how to add a dropdown list to the
admin\regions_form.html.erb page that would show the countries I have
added using admin/countries/new.

If your region belongs_to country, then you could do something like this
(inside a form_for for the region):

<%= f.collection_select :country_id, Country.order(:name), :id, :name %>

Walter

Thanks! That got me going in the right direction. The one tricky part
was that my items are in the admin folder, so this ended up being the
format:

<%= f.collection_select :country,
Admin::Country.order(:sort_order,:country), :id, :country %>

I have now ran into another issue.

I have a field like this on my _form.html page:

<%= f.collection_select :address_region, Admin::Region.order(:region),
:id, :region, :include_blank => true %>

This works fine, but if I don’t select a value (which is okay) I can not
later edit the record. If I try to, I get:

Couldn’t find Admin::Region without an ID

Is there anyway to edit the form if users have left the field blank?