huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-May-22 11:52 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gundestrup-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-May-22 12:13 UTC
Re: restful routes question
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 huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
(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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
huard.elise-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-May-22 12:48 UTC
Re: restful routes question
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- s.net> wrote:> (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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---