belongs_to association and formtastic
Asked Answered
K

2

1

I have a model Product which has a belongs_to association with another model Type. In the product's form, I'm using formtastic to display a select tag with all the types available in the database, like this:

<%= f.input :type %> 

The select is showing up OK, but each option of it is an object instance of the Type model as a string, for example:

#<Type:0x00eff180c85c8>

Instead of that, I'd like to display the 'title' attribute of it, like:

Electronic
Domestic
...

Any ideas?

Knob answered 9/6, 2013 at 23:12 Comment(0)
B
2

Try the member_label option, it sounds like what you want to do:

<%= f.input :type, :member_label => :title %>

The documentation has more examples.

Boise answered 21/6, 2013 at 7:18 Comment(0)
V
1

Simply add this in your model

  def name
    return self.title
  end
Vann answered 14/1, 2018 at 14:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.