I'm not sure how to do write a query. The issue:
I have two tables, authorities
and notices
each one with this column:
t.string "tags", default:[], array:true
I need to check if at least one element from the authorities
array is in the notices
array and save it on a class variable. So far I've tried this line of code in my controller:
@noticias = Notice.where('tags @> ARRAY[?]',current_authority.tags)
I tried something like this in the view:
<% @noticias.each do |notice| %>
<% notice.nombre %>
<% end %>
EDIT
Thanks for you answers but my problem was
ERROR: operator does not exist: character varying[] @> text[]
the solution is:
@noticias = Notice.where('tags && ARRAY[?]::varchar[]',current_authority.tags)
As explained here If array contains value