Given you have Rails e-commerce website.
There are Product and Category models which have has_and_belongs_to_many relationship.
models/product.rb
class Product
has_and_belongs_to_many :categories
endmodels/category.rb
| # frozen_string_literal: true | |
| class Array | |
| module Mixins | |
| # Mixing for providing flatten method into Array | |
| module Flatten | |
| # Returns a flatten copy of array | |
| # Example: [[1,2,[3]],4].recursive_flatten => [1, 2, 3, 4] | |
| def recursive_flatten(result: []) | |
| each do |element| |
Given you have Rails e-commerce website.
There are Product and Category models which have has_and_belongs_to_many relationship.
models/product.rb
class Product
has_and_belongs_to_many :categories
endmodels/category.rb