I’ve got this list of objects out from my HalfLink model, like:
@itemhl = HalfLink.find_all_by_item_id(@item, :include => :other_item)
id | item_id | other_item_id | other_item_category_id
1 | 1 | 2 | 1
2 | 1 | 3 | 4
3 | 1 | 4 | 3
4 | 1 | 6 | 1
5 | 1 | 8 | 3
6 | 1 | 7 | 4
and I want to convert it to display in my view as:
Name of category 1
Name of category 3
name of category 4
It only shows categories that are present, and groups by unique categories
I know the normal way is to link the ActiveRecord such that i can do Category.other_items but due to other issues, this isn’t very practical at the moment.
Is there any other way of setting this up? Should I build an array?
Some other lines i have are:
@item_categories = @itemhl.map{|c| c.other_item.category.name }.uniq
You already have the code to retrieve items you want:
Now to convert it into more presentable form, you can do something like this: