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)
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!
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!