This project is archived and is in readonly mode.

#4485 ✓invalid
Wincent Colaiuta

:as option not working as expected in new Rails 3 router DSL

Reported by Wincent Colaiuta | April 27th, 2010 @ 08:09 AM | in 3.0.2

In my Rails 2.3.5 app I have an ArticlesController and I use the :as option in my config/routes.rb to give me paths like "/wiki/foo" instead of "/articles/foo".

I'm trying to rewrite the same routes using the new DSL and can't get the same result. These resources suggest that the same ":as => 'foo'" idiom should continue to work with resources in the new DSL:

But doesn't seem to work...

resources :articles, :as => 'wiki'

Yields:

          GET    /articles(.:format)                                            {:controller=>"articles", :action=>"index"}
    wikis POST   /articles(.:format)                                            {:controller=>"articles", :action=>"create"}
 new_wiki GET    /articles/new(.:format)                                        {:controller=>"articles", :action=>"new"}
          GET    /articles/:id(.:format)                                        {:controller=>"articles", :action=>"show"}
          PUT    /articles/:id(.:format)                                        {:controller=>"articles", :action=>"update"}
     wiki DELETE /articles/:id(.:format)                                        {:controller=>"articles", :action=>"destroy"}
edit_wiki GET    /articles/:id/edit(.:format)                                   {:controller=>"articles", :action=>"edit"}

Compare that with the output for 2.3.5, where:

map.resources :articles,:as => :wiki

Yields:

    articles GET    /wiki(.:format)                                                {:controller=>"articles", :action=>"index"}
             POST   /wiki(.:format)                                                {:controller=>"articles", :action=>"create"}
 new_article GET    /wiki/new(.:format)                                            {:controller=>"articles", :action=>"new"}
edit_article GET    /wiki/:id/edit(.:format)                                       {:controller=>"articles", :action=>"edit"}
     article GET    /wiki/:id(.:format)                                            {:controller=>"articles", :action=>"show"}
             PUT    /wiki/:id(.:format)                                            {:controller=>"articles", :action=>"update"}
             DELETE /wiki/:id(.:format)                                            {:controller=>"articles", :action=>"destroy"}

In other words, under 2.3.5 the :as option on a resource causes the path in the URL to change but not the names of the generated URL helper methods.

Under 3.0 the :as option on a resource does the opposite, changing the names of the generated URL helper methods but not the path in the URL itself.

Is this intended behavior (in which case we're probably talking about a documentation bug) or an implementation bug? Or am I misreading the documentation and should be doing this in another way?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages