I’ve been working with option_groups_from_collection_for_select and haven’t seen a way to utilize it on a form tied to a model without hard coding the select tags. While I’ve only been working in Rails for a few weeks, it would seem like there is a better way to do this (eg. collection_select or even select).
Is there a “Rails Way” to avoid hard coding the < select > tag when using option_groups_from_collection_for_select?
Code from my view (site has_many categories and I’m trying to group my list by Site)
<select id="item_category_id" name="item[category_id]">
<%= option_groups_from_collection_for_select(Site.all, :categories, :name, :id, :name, @item.category_id) %>
</select>
Are you working with an object in a form_for? If so does this generate what you need:
or without the form_for
Peer