开发者

has_many :through formtastic multi-select field

开发者 https://www.devze.com 2022-12-30 23:46 出处:网络
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:

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 http://web9.twitpic.com/img/103694166-98ad71116216d3d1b12dd77690b36248.4bf6ca20-full.jpg


What you are seeing in the to_s method of an ActiveRecord::Base object. The hex number is the memory location which would be different each request. After poking around the Formastic code, it looks for methods from a predefined list to find the text to display.

Make sure your Sic model has a field (or method) in this list to_label, display_name, full_name, name, title, username, login, value, to_s that returns the text you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消