Sigh, yeah, there's always that way. So unrailsy... but probably what I'll end up doing. Or I could patch Resources to make it push any unclaimed options into params. But parsing the URI by hand is probably easier.
On Wed, Oct 1, 2008 at 8:35 PM, Greg DeVore <[EMAIL PROTECTED]> wrote: > > Ian- > I don't know how you would do that in the way you are describing. One > possibility though would be to do this: > > map.resources :sons, :controller => "papas" > map.resources :daughters, :controller => "papas" > > This will point both routes to the papas controller. You won't see > "sons" or "daughters" come through as params. But you can query > request.env['REQUEST_URI'] and you would get back something like '/ > sons/new/'. > > So: > 1. request.env['REQUEST_URI'].split("/") will give you an array > ["","sons","new"] > 2. access [1] of the array and you will have your parameter. > > A little convoluted but I think that it would do what you want. > > Greg > > > On Oct 1, 2008, at 6:12 PM, Ian Smith-Heisters wrote: > >> >> Sure. You have it basically right, but let me elaborate. >> >> I have models like so: >> >> class Papa < ActiveRecord::Base; abstract_class = true; end >> class Daughter < Papa; end >> class Son < Papa; end >> >> I have this controller: >> >> class PapaController < ApplicationController >> def new; @model = new_model; end >> def new_model >> params[:type].classify.constantize.new # there's more safety logic >> here in reality, but this is the gist >> end >> end >> >> I started with the default route: >> >> map.resources :papa >> >> So, then, I can create a new son by doing GET /papa/new?type=son, >> which is fine, but not ideal. Ideally, I would do GET /son/new, but it >> would still use the Papa controller, and set params[:type] to "son". >> This is what I have right now: >> >> map.resources :papa, :path_prefix => '/:type' >> >> which allows me to GET /son/papa/new, and create links like >> papa_path(@model.type.to_s.downcase, @model). >> >> So the question is how to make these specs pass: >> >> params_from(:get, "/son/new").should == {:controller => 'papa', >> :action => 'new', :type => 'son'} >> params_from(:get, "/daughter/new").should == {:controller => 'papa', >> :action => 'new', :type => 'daughter'} >> >> Is that clearer? >> >> Thanks, >> Ian >> > > > > --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---