Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Austin Klenk
Austin Klenk
4,399 Points

Getting Mysql Hash Return in Rails Dropdown

Im getting a Hash return in Rails for the associations

#<Make:0x007fc33d280bd8>
<%= f.association :make %>

I'm using simple form

3 Answers

Brandon Barrette
Brandon Barrette
20,485 Points

So I don't really like simple_form because it appears so simple in the beginning, but then when you need to actually do out of the ordinary forms, it becomes too hacky.

Try this:

   f.association :make, collection: Make.all, label_method: :title, value_method: :id

I used :title, I don't know what attribute on the Make class stores the name.

Getting this from here: http://stackoverflow.com/questions/19262954/specify-values-in-simple-form-association

Austin Klenk
Austin Klenk
4,399 Points

That worked but i had to specify the label_method like you said to :make

so you recommend don't use simple form?

Brandon Barrette
Brandon Barrette
20,485 Points

I wouldn't say never use it. Just know how to write forms without it. It's always so magical, but you should really understand how the underlying form field building.

Brandon Barrette
Brandon Barrette
20,485 Points

Is "Make" the attribute for another class or a class itself?

Austin Klenk
Austin Klenk
4,399 Points

class itself, different controller.

Brandon Barrette
Brandon Barrette
20,485 Points

Can you show the model of the form object?

Does it have a has_many :makes, has_one: make?

Austin Klenk
Austin Klenk
4,399 Points

Make Model

class Make < ActiveRecord::Base
    has_many :campers
end

Camper Model

class Camper < ActiveRecord::Base
    has_one :customer
    belongs_to :customer
    has_many :workorders
    belongs_to :make
end