# Restful routes question

**URL:** <https://www.ruby-forum.com/t/restful-routes-question/138380>\
**Category:** Rails\
**Created:** [May 22, 2008, 1:53pm UTC](https://www.ruby-forum.com/t/restful-routes-question/138380 "2008-05-22T13:53:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 22, 2008, 1:53pm UTC](https://www.ruby-forum.com/t/restful-routes-question/138380/1 "2008-05-22T13:53:21Z")

</div>

Hi,

a small question about restful routing.

Imagine i have an application with channels and videos  
A channel contains videos.  
So i have in my routes.rb:  
map.resources :channels, :has\_many =\> :videos

But i have one problem: some actions concern all videos across all  
channels.  
So say i add in my routes.rb:  
map.resources :videos  
on top of the one above.

The problem is that both routes point to the same controller :  
VideosController.  
This controller risks becoming a little awkward.

What is your advice ? how to cleanly split this ? use namespaces ?  
Thank you,

Elise

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 22, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/restful-routes-question/138380/2 "2008-05-22T14:15:11Z")

</div>

Dear Elise

make your relations in your modul:  
Channel model:  
has\_many :videos

Video model:  
belongs\_to :channel

Routing:

map.resources :channels do |channel|  
channel.resources :videos

map.resources :videos

regards  
svend

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 22, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/restful-routes-question/138380/3 "2008-05-22T14:27:07Z")

</div>

(I may be mistaken, but I think the ap.resources :channels, :has\_many =\>  
:videos provides also the non-nested routes)

I guess my controllers are akward by your standards 🙂 but when I face  
this requirement I usually just check if the parent object exists or  
not. So in by before\_filter I do:

@channel = Channel.find(params[:channel\_id] rescue nil

And the index (for example)

def index  
if @channel  
@videos = @channel.find…  
else  
@videos = Video.find…  
end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 22, 2008, 2:48pm UTC](https://www.ruby-forum.com/t/restful-routes-question/138380/4 "2008-05-22T14:48:44Z")

</div>

thanks Abigail - that’s what i’ve been doing so far as well, no insult  
intended 🙂  
just wondered if there was different way to handle this.  
Thanks,

Elise

On May 22, 2:27 pm, Abigail Headroom \<rails-mailing-l…@andreas-
