Rails table inheritance issue

Posted by Tristan O'Neil on Stack Overflow See other posts from Stack Overflow or by Tristan O'Neil
Published on 2010-06-08T17:40:35Z Indexed on 2010/06/08 17:42 UTC
Read the original article Hit count: 241

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby