Restful routes question

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

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

(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 :slight_smile: 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

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

Elise

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs