views:

28

answers:

1

I've setup some models in the table inheritance fashion and everything seems to be all fine and dandy. But, when I use a collection select field to select values from one of the models it saves it but it saves the ID of the data and not the actual value of the data. So when I try to display the value on the show view it just shows the corresponding ID and not the actual value.

Here is my setup. I'm using formtastic as a side note.

View

<%= show_field "County", @company.county %>

Form

<%= f.input :county, :label => 'County', :as => :select, :collection => County.find(:all) %>

Base Model

class Tag < ActiveRecord::Base
      before_create :set_type
      before_update :set_type
      attr_accessible :type, :name, :category
      belongs_to :company

      def set_type
        self.type = self.category
      end
end

Inherited Model

class County < Tag
end
A: 

The tag/county is supposed to store the id not the value. Within your view you can then reference the name field of the county, or whichever field you wish to show

<%= show_field "County", @company.county.name %>
Steve Weet