Tag ruby-on-rails

[Solved] How to find out the number of records in a table? [closed]

It would be something like this on your model: def self.pending_count where(status: 0).count end def self.in_progress_count where(status: 1).count end def self.finished_count where(status: 2).count end Then you can just call Model.pending_count (or the other methods) wherever you need it. solved How…

[Solved] Initialize Ruby codes error

class Dog def set_name(name) @dogname = name end def get_name return @dogname end def talk return “awww” end def initialize(title, description) @title = title @description = description end end #That will cause an error because your new method have two…

[Solved] Rails: Remove Curly Braces in Array [closed]

@temp = SalesOrder.where(“status > ?”, 0).ids items = SalesOrderItem.where(sales_order_id: @temp).where.not(product_id: nil) total = items.to_a.group_by(&:product_id).each_with_object({}) do |(product_id, quantity), total| total[Product.find(product_id.to_i).name] = quantity.map(&:quantity).map(&:to_f).sum end @top_five = total.sort_by { |k, v| v }.reverse! Check this. It should work. If any errors, ping me,…