I have a model called appointment
. Each appointment
has a stylist
. In the form where I create a new appointment
, I'm doing this:
<div class="field">
<%= f.label :stylist_id %><br />
<%= f.select(:stylist_id, Stylist.order("name").map { |s| [s.name, s.id] }) %>
</div>
This works but it's going to be tedious to do this kind of thing for every association in my app. I imagine Rails has some way of automatically generating select fields for associations but I have no idea how it works. Does such a thing exist?
Oh, and by the way, I already know about scaffolding. If scaffolding is supposed to take care of what I describe above, I'm apparently doing something wrong, because it's not doing that for me.
(I'm on Rails 3.)
Hmm, it seems that collection_select would work for the typical scenario:
<%= f.collection_select :stylist_id, Stylist.all, :id, :name %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With