How can I get unique values from column in the table? For example, I have this Products table:
ID NAME CATEGORY 1 name1 1st_cat 2 name2 2nd_cat 3 name3 1st_c
This does all the work in the database server. The result is a simple array.
<% Product.distinct(:category).pluck(:category).each do |category| <%= category %> <% end %>
Rails will generate SQL that works on any database (Postgres, MySQL, etc).
SELECT DISTINCT "products"."category" FROM "products"