This doesn't answer your question, but have you thought about storing the position as an integer in the database? Would that be an option? Depending on what you want to do, it might be over-engineering, but it could simplify the view. If you had a position column, you might do something like this:
In the controller:
# Margarita (position == 1), Bourbon (position == 2), Beer (position == 3), and so on@cocktails=Cocktail.order(:position)
In the view:
<%=render@cocktails%><!-- or --><%@cocktails.eachdo|cocktail|%><%=cocktail.name%><%end%>
It might be something to take a look into as you think about drink groups.
I'm a Staff Software Engineer at Cisco. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
This doesn't answer your question, but have you thought about storing the position as an integer in the database? Would that be an option? Depending on what you want to do, it might be over-engineering, but it could simplify the view. If you had a position column, you might do something like this:
In the controller:
In the view:
It might be something to take a look into as you think about drink groups.
That makes sense! It’s a good solution. I’ll look into it. Thanks!