On 4 March 2013 15:35, Anthony DeFreitas <
ant...@caribbeanhotels.com> wrote:
> I have the following models:
>
> Category:
> has_many :sub_categories
>
> Sub_Category:
>
> belongs_to :category
> has_many :posts
>
> Post:
> belongs_to :sub_category
>
> I'm trying to build a page that will list Categories with Pjax tabs and then
> each Category tab will list all it's Sub-Categories in widgets with 5 posts
> in each widget.
>
> I have an idea of how to loop through the data once I have it but I'm having
> trouble structuring the query. Thanks for any help.
>
> @category.sub_categories.each do |sub_cat|
> sub_cat.posts.each_slice(5) do |posts|
> #here you create a widget, posts have at most 5 elements thanks to
> each_slice method
> posts.each do |post|
> #do something with each post
> end
> end
> end
It is not clear to me what question you are trying to ask here.
Colin