I have the following models
Document
has_many :document_categorizations
has_many :document_categories, through: :document_categorizations
DocumentCategory
has_many :document_categorizations
has_many :documents, through: :document_categorizations
DocumentCategorization
belongs_to :document_category
belongs_to :document
In my index action, I can filter the documents by category...
def index
if params[:category_id].nil?
@documents = Document.page(params[:page]).per(15)
else
@documents = DocumentCategory.find(params[:category_id]).documents
@category = DocumentCategory.find(params[:category_id])
end
....
end
I can't use DocumentCategory.find(params[:category_id]).documents
anymore because I just added kaminari for pagination and I need to make the query at the Document model not DocumentCategory.
How can I query for documents of a certain category?