I have two models in my rails 5 application:
class Post < ApplicationRecord
has_many :tags
end
class Tag < ApplicationRecord
belongs_to :post
end
In my data base I have for example two post with 2 different tags each. How can I search my post by two specifics tags (tag.title="tagname1" AND tag.title="tagname2"):
Post.includes(:tags).where(tag: {title: "tagName1"}).where(tag: {title:
"tagName2"})
thanks