I am doing the recipe/category example, but with a
has_many_and_belongs_to relationship. To select categories for a
recipe, I have a select control. When editing, I want the proper
categories selected. In order to get it to work, I put this in my
_form.rhtml:
<select id="recipe_categories"
name="recipe[category_ids][]" size="4"
multiple>
<%= options_from_collection_for_select( @categories,
''id'', ''name'',
@recipe.categories.map{|t| t.id}) %>
</select>
Is this the best way to do this?
~S
