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

On Wed, Oct 1, 2008 at 6:19 AM, gdevore <[EMAIL PROTECTED]> wrote:
>
> Ian-
> It might be helpful if you gave a few more examples of what you want
> to accomplish.  Are you trying to have the following routes all point
> to the "new" method on the same controller?
>
> /foo/new
> /bar/new
> /somethingelse/new
>
>
> Greg DeVore
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to