How about construct a class CoktailList that fetch and store the records from database as a hash in a instance variable, and delegate the [] method to that variable?
Just to add a example of implementation:
In cocktail_list.rb
classCocktailListdefinitialize(scope=:all)@list=Cocktail.send(scope).index_by(&:name)end# put any desirable hash method heredelegate:size,:keys,:values,:each,:[],to: :@listend
In controller:
@cocktail_list=CocktailList.new# or CocktailList.new(:for_sale)
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.
How about construct a class CoktailList that fetch and store the records from database as a hash in a instance variable, and delegate the [] method to that variable?
Just to add a example of implementation:
In cocktail_list.rb
In controller:
In view:
Ooh that would be clean too!