I''ve noticed that nested resources are also available via the default route: In my application I have many gamers and want to give them a singleton profile resource (example.com/gamers/3/profile). So my config.routes includes: map.resources :gamers, :has_one => [:profile] Even though it''s a singleton, my controller has be pluralized: called ProfilesController and live at app/controllers/profiles_controller.rb with views in app/views/profiles. The problem I see is that the default route also means that the profiles controller can be accessed at example.com/profiles. Should I write a before_filter to raise 404 if it can''t find params[:gamer_id]? It seems the natural place to do this would be config/routes, but the only way to do that would be to remove the default route and explicitly list all of my other controllers. Is there a nicer way to do this that I''m missing? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
A question I''m tempted to ask is: why do you need to separate a gamer and their profile? Why not just store the profile information on a gamer? -- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 20, 9:20 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> A question I''m tempted to ask is: why do you need to separate a gamer and > their profile? Why not just store the profile information on a gamer?I''m going to be adding several sub-controllers to my gamers controller; I just gave this as the simplest example. You''re right that it makes sense to store profiles on the gamer objects. Anyone have a solution for the routing, though? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Defining a before_filter seems like the least painful way to go about it. On Dec 21, 2007 12:58 PM, Peter Harkins <google-geYGz4ndBgWvxtuIKfZzQg@public.gmane.org> wrote:> > On Dec 20, 9:20 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > A question I''m tempted to ask is: why do you need to separate a gamer > and > > their profile? Why not just store the profile information on a gamer? > > I''m going to be adding several sub-controllers to my gamers > controller; I just gave this as the simplest example. You''re right > that it makes sense to store profiles on the gamer objects. > > Anyone have a solution for the routing, though? > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 20, 9:40 pm, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Defining a before_filter seems like the least painful way to go about it.Hm, it doesn''t seem to be testable. I wrote: def nested puts request.url raise ActionController::RoutingError, ''not nested'' unless params[:gamer_id] end And that works fine. But when I try to test an action: def test_edit alice = gamers(:alice) # and any of the following: get :show, :gamer => alice get :show, :gamer => alice.to_param get :show, :gamer_id => alice get :show, :gamer_id => alice.to_param end I just get the RoutingError... it says I''m requesting the url http://test.host/profiles/edit/alice instead of the correct url of http://test.host/gamers/alice/profile/edit. How do I tell the functional test to use the more-specific (and earlier in config.routes!) route instead of the default route? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What''s wrong with doing it a little simpler? private def check_for_gamer_id redirect_back_or_default(default_controllers_path) if params[:gamer_id].nil? end -- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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''d rather serve a 404 than 301 in this case. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
raise the RoutingError and then say in your tests that the show page should raise error. I''ve only ever done RSpec testing so I''m not much help on the baked-in Rails testing front. On Dec 21, 2007 2:37 PM, Peter Harkins <google-geYGz4ndBgWvxtuIKfZzQg@public.gmane.org> wrote:> > I''d rather serve a 404 than 301 in this case. > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---