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!
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

Austin Klenk
4,399 PointsGetting 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
20,485 PointsSo 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

Brandon Barrette
20,485 PointsIs "Make" the attribute for another class or a class itself?

Austin Klenk
4,399 Pointsclass itself, different controller.

Brandon Barrette
20,485 PointsCan you show the model of the form object?
Does it have a has_many :makes, has_one: make?

Austin Klenk
4,399 PointsMake 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
Austin Klenk
4,399 PointsAustin Klenk
4,399 PointsThat worked but i had to specify the label_method like you said to :make
so you recommend don't use simple form?
Brandon Barrette
20,485 PointsBrandon Barrette
20,485 PointsI 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.