Routing error/difference between RC and Beta4

In beta4 I could do this:

  resources :sections do
    get :new, :on=>:member

But not with RC

If I change "new" to be something else, it will work

So it seems that "new" is now treated like a reserved word of sorts?

I really need to share the new method between "sections/new" and
"sections/1/new" because my structure is a tree, so it makes sense to



is so much cleaner (and dry) compared to


Anyone have an opinion or suggestion?


Just tried my project from scratch and generated using rails RC,
rather than just changing the version in the Gemfile.

Didn't work, but was worth testing :slight_smile:

If anyone has an idea, or a thought of why this change was made, would
be good to hear

cheers :slight_smile:

Did you open an issue for this? if not would you mind to do it so it
can be discussed there?.

Symbols are reserved in the Rails 3 Router DSL (they are used
internally). Consequently, we do not expose `get :new` as public API,
so we don't have tests for it causing its behavior change between
releases due to internal needs.

Bottom line is: you should always use strings. :slight_smile:

It was done as part of some changes to add back support for custom new actions e.g. /posts/new/preview. To support this we added new scope to resources to match member and collection scopes. So whereas before 'new' would be added to the path scope, in RC it doesn't because new_scope has already added new to the path.

You can specify your routes as follows to get the effect you need:

  resources :sections, :id => /.+/ do
    get :new, :path => 'new', :on => :member

However you'll still need to address the create, edit and update actions plus you'll need to override the :id constraint which doesn't allow slashes. Also the show action comes before the edit action so the greedy regexp needed for :id will match the edit url. You would be better off manually specifying each of the routes individually - it'll be easier than trying to bend resources to what you want:

  scope('sections', :controller => 'sections', :id => /.+/) do
    get '/(:id)/new' => :new, :as => :new_section
    get '/:id/edit' => :edit, :as => :edit_section
    get '/:id' => :show, :as => :section
    put '/:id' => :update, :as => :section
    delete '/:id' => :destroy, :as => :section
    get '/' => :index, :as => :sections
    post '/(:id)' => :create, :as => :sections

This set of routes should do what you need.