This project is archived and is in readonly mode.
: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:
- http://guides.rails.info/3_0_release_notes.html
- http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/
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
-
Wincent Colaiuta April 28th, 2010 @ 06:32 PM
Can someone involved on the API design comment on this one? If I can just get some clarification on whether this is a doc bug, an implementation bug, or user error, then I can work on a fix.
-
Santiago Pastorino April 29th, 2010 @ 03:59 PM
- State changed from new to invalid
Wincent as changes the named route only i'm going to change the guides, thanks ;).
-
José Valim April 29th, 2010 @ 04:00 PM
- Milestone cleared.
- Assigned user set to José Valim
It's intended behavior. Although not consistent with the previous API, the new router API is consistent internally in a sense that:
- :path always changes the path
- :as always changed the named url helper
-
Wincent Colaiuta April 29th, 2010 @ 04:40 PM
Cool. :path does exactly what I want/need.
BTW I haven't seen the ":path" parameter mentioned anywhere. The official guide only mentions ":path_names", as does Yehuda's article.
-
José Valim April 29th, 2010 @ 04:41 PM
Yeah, the DSL was inconsistent and we fixed and added :path just in beta 3.
-
Wincent Colaiuta April 29th, 2010 @ 04:46 PM
Well, it certainly looks more consistent now. Good job on that. (In 2.3.5 I had a fairly ugly routes file, about 100 lines long. With the new DSL it's still almost the same length, but it's much clearer now and the amount of repetition and crud is greatly reduced.)
-
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to Low
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>