ruby - Rails has_and_belongs_to_many query -
i have next database schema in rails 4 application
users >---tags_users---< tags >---posts_tags---< posts
given logged in user, best way me of posts (from users) match there tags tags interested in.
you can pass array model#where
array of posts choosed criteria.
def show_by_tags @posts = post.all array_of_tags.each |tag| @posts.where(tag_name: tag) end end
ruby-on-rails ruby rails-activerecord
No comments:
Post a Comment