Association_to association and formtastic

I have a model product that has an association belonging to another model. In the product form, I use formtastic to display the select tag with all types available in the database, for example:

<%= f.input :type %> 

The selection is displayed OK, but each of them is an instance of the type model object as a string, for example:

 #<Type:0x00eff180c85c8> 

Instead, I would like to display the attribute 'title', for example:

 Electronic Domestic ... 

Any ideas?

+1
source share
2 answers

Try the member_label parameter, it looks like what you want to do:

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

The documentation contains more examples.

+2
source

Just add this to your model.

  def name return self.title end 
+1
source

Source: https://habr.com/ru/post/913192/


All Articles