I am trying out Tire gem for my Demo Rails app to implement ElasticSearch.
So, here are my models associations :-
A User belongs to many UserGroups. And Every UserGroup has many Post associated with it.
So, this is what I do to show all the posts for a User in posts_controller.rb
def index
@user_groups = current_user.user_groups
for group in @user_groups
for p in group.posts
@posts = @posts.to_a.push p
end
end
end
Now, I want to add search functionality to it. A User may be able to search for a Post from all the Post that are visible to him.
So, I have two questions which are connected to each other.
Q1. How, do I add the search functionality by using the Tire gem for the User so that the user may search from the Posts that are visible to him ? Tire allows to directly search on a model using
@posts = Post.search(params[:query])
But, I want to search from an array.
Q2. And Secondly, Is my approach correct, by first storing the concerned Posts in an array and then use Tire to search from that array ?