On 25 November 2015 at 17:55, fugee ohu <fugee...@gmail.com> wrote:
> doesn't leave much for the controller ... just set category?

If that is all you need in the view then yes.  You could instead put
in the controller something like

@listings = []
@category.each do |category|
  @listings += category.listings
end

but I don't see the point.  All you would be avoiding is the outer
level of 'each' loop in the view, and if anything it makes the code
less easy to understand.

There is likely a way of coding a query as you originally suggested,
and if there were going to be tens of thousands of categories then it
might even be worth it, but I always prefer the KISS principle until
it is proven that any benefit is worth the brain strain involved in
working it out.  Life is too short.

Colin

>
> On Wednesday, November 25, 2015 at 11:56:06 AM UTC-5, Colin Law wrote:
>>
>> On 25 November 2015 at 16:46, fugee ohu <fuge...@gmail.com> wrote:
>> >  I'm sorry, i meant to say in the side pane should be links to only the
>> > immediate children categories, not all descendants, just the next level
>>
>> So in the side pane
>> @category.children.each do |category|
>>   category.name (or whatever)
>> end
>>
>> and if in the main pane you want the listings for all descendant children
>> @category.descendants.each do |category|
>>   category.listings.each do |listing|
>>     # show listing data
>>   end
>> end
>>
>> Colin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/a0f9a98b-28e2-4e7d-8f5e-2e4b5f863f8b%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLud%2BT0bQuj5YfGjeriNd12mE0cipwiFyPPc%2B77VzTu8Yw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to