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.
Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
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
pluck
which 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?