If you really want to make the query maximally efficient, you could use pluck which would return an array of arrays containing the values you need. So...
In the controller:
@cocktails=Cocktail.for_sale.pluck(:name,:description,:price)# @cocktails[0] would look like ["margarita", "Good drink", 9] or whatever.
I'm a Sr. Software Engineer at Flashpoint. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
Ok, that makes sense. Scopes and pluck are definitely very useful features to know about. Is there any specific reason that you're sticking to using an array rather than converting to a hash? Or just because arrays are simpler to get to?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
What about...
In the controller:
Helper:
This way you select from the array each time.
If you really want to make the query maximally efficient, you could use
pluckwhich would return an array of arrays containing the values you need. So...In the controller:
Helper:
I might be offbase in how I'm thinking about this, but at least it might help you look up some of these methods for use now and/or future.
Ok, that makes sense. Scopes and pluck are definitely very useful features to know about. Is there any specific reason that you're sticking to using an array rather than converting to a hash? Or just because arrays are simpler to get to?