has_many :through formtastic multi-select field

Posted by Tristan O'Neil on Stack Overflow See other posts from Stack Overflow or by Tristan O'Neil
Published on 2010-05-21T17:48:22Z Indexed on 2010/05/21 17:50 UTC
Read the original article Hit count: 415

Filed under:

I'm trying to set up a many to many relationship using the has_many :through method and then use a multi-select field to setup the relationships. I'm following this tutorial:

http://asciicasts.com/episodes/185-formtastic-part-2

However for some reason the form displays a strange hex number and it changes each page refresh, I'm not exactly sure what I'm doing wrong. Below is my model/view code.

company.rb

has_many :classifications
has_many :sics, :through => :classifications

sic.rb

has_many :classifications
has_many :companies, :through => :classifications

classification.rb

belongs_to :company
belongs_to :sic

_form.html.erb

<% semantic_form_for @company do |f| %>
<% f.inputs do %>
    <%= f.input :company %>
    <%= f.input :sics %>
<% end %>
<%= f.buttons %>
<% end %>

Also here is the the form looks like it's showing the correct number of entries for the field but it is clearly not showing the correct name for the relationship.

SIC Multi-Select

© Stack Overflow or respective owner

Related posts about ruby-on-rails