Posts

Showing posts with the label array

The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Array

 res.end() to res.send()

Custom order of Record | | Order as specified || order_as_specified

Custom order of Record | | Order as specified || order_as_specified Install gem gem 'order_as_specified' bundle install or gem install order_as_specified write this line at top of your model / /that model you have to fetch record in custom order extend OrderAsSpecified Now in your controller method ids=[1,3,5,6,7,4,2] // assuming you have 7 record with this id's & and you want records in this order then Model.where(id: ids).order_as_specified(id: ids) //this will give you record in custom order Here is Working Example def index    premia1 = []    premia2 = []    PremiumInstruction.all.select{|pi| premia1 << pi.premium}    Premium.all.select{|p| premia2 << p if p.premium_instructions.blank?}    permia = premia2 + premia1.uniq //add both array    ids = permia.pluck(:id) //getting ids from array into an array //learn about pluck in other post    @collection = Premium.where(id: ids). order_as_specified (id: ids) end Here we