Answer the question
In order to leave comments, you need to log in
How to pull dimensions from a collection of objects in rails?
There are categories, there are sub-categories and there are products, products have a size, each product has its own size, all sizes are different, for example, for refrigerators from 5 to 10 and for microwaves from 0.5 to 3, as on the page with products of a certain sub-category dynamically pull out all the sizes that belong to subcategories, grouped by size for example from 6 to 10?
Where to dig? how to do it?
Can create a size model to associate with subcategories or what?
So that the links were according to this principle
diameter: 6...10 11...40 41...59 60...80 82.5...114 118...152 152.4...203 219...325 330 ...555
Now it looks like this:
Goods
class Item < ActiveRecord::Base
belongs_to :sub_category, foreign_key: 'category_id'
has_many :cart_items
has_many :carts, through: :cart_items
end
class SubCategory < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
belongs_to :category
has_many :items, foreign_key: "category_id"
def normalize_friendly_id(input)
input.to_s.to_slug.normalize(transliterations: :russian).to_s
end
end
Answer the question
In order to leave comments, you need to log in
Item.where(:category_id => your_category_id, :size => 6..10)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question