<%% form_for(@<%= singular_name %>) do |f| %>
  <%%= f.error_messages %>

  <fieldset>
    <legend><%%= t('<%= singular_name %>', :count => 1).humanize %></legend>

<% for attribute in attributes -%>
    <div>
      <%%= f.label :<%= attribute.name %>, t('<%= "attribute.#{attribute.column.name}" %>') %>
<% if attribute.name =~ /_id\Z/ -%>
<% association = attribute.name.sub(/_id\Z/, '') -%>
      <%%= f.collection_select :<%= attribute.name %>, @<%= association.pluralize %>, :id, :name,
        {:prompt => t('select_prompt')} %>
<% else -%>
      <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
<% end -%>
    </div>
<% end -%>

    <hr />
    <%%= f.submit t('save') %>
  </fieldset>
<%% end %>


<%% form_for(@<%= singular_name %>) do |f| %>
  <%%= f.error_messages %>

  <fieldset>
    <legend><%%= t('<%= singular_name %>', :count => 1).humanize %></legend>

<% for attribute in attributes -%>
    <div>
      <%%= f.label :<%= attribute.name %>, t('<%= "attribute.#{attribute.column.name}" %>') %>
<% if attribute.name =~ /_id\Z/ -%>
<%
  association = attribute.name.sub(/_id\Z/, '')
  label_attribute = association.camelize.constantize.column_names.include?('name') ? 'name' : 'id'
-%>
      <%%= f.collection_select :<%= attribute.name %>, @<%= association.pluralize %>, :id, :<%= label_attribute %>,
        {:prompt => t('select_prompt')} %>
<% else -%>
      <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
<% end -%>
    </div>
<% end -%>

    <hr />
    <%%= f.submit t('save') %>
  </fieldset>
<%% end %>


Use id for label in form select when there's no name attribute in the associated model
Use id for label in form select when there's no name attribute in the associated model
