This project is archived and is in readonly mode.
Inappropriate route
-
Damien MATHIEU
I've written a test that should fail with that (see attached).
However it seems in edge it works fine.
The tests I made yesterday were on beta3 (I know I should have tested on edge). I'll test it deeper with edge. -
Damien MATHIEU
FYI even though the test goes well, I still get the same in my application.
-
Jeremy Kemper
- Milestone cleared.
- State changed from new to open
- Assigned user set to josh
-
José Valim
Can you please provide a failing test case on master then?
-
Damien MATHIEU
- Assigned user cleared.
As said before, I couldn't reproduce it in a test. And that's for a very simple reason. It's a mistake from my side on the application, not from rails.
-
José Valim
- Assigned user set to José Valim
When you do "url_for(@category)", it's going to generate "category_url" based on the @category resource given. category_url will then generate "/categories/test" which becomes "/categories/test?lang=en" with the extra lang parameter.
This can be verified if we look to the
rake:routeoutput you gave to us:category DELETE /categories/:id(.:format) {:controller=>"categories", :action=>"destroy"}In other words, to have the behavior you expect, category_url should point to "/:lang/:category_id". You can try the following definition:
scope '/:lang' do match ':category_id', :to => 'categories#show', :as => :category root :to => 'categories#index' endJust then category_url is going to point to the route you expect. If not, we may have a routes bug.
-
Damien MATHIEU
I didn't do a match for categories#show because I have other routes belonging to the category.
In fact the problem was just because of routing priorities with the resources. Now that I define them before the lang scope, it works well. -
José Valim
- State changed from open to invalid
Sweet! Can you post your new routes just as reference for other ppl? Thanks!
-
Damien MATHIEU
Yeah of course.
I've decided to move the admin pages to a scope too. So in the end, I get the following :scope '/me' do resources :pages, :except => [:index, :show] resources :categories, :except => [:index, :show] end scope '/:lang' do scope '/:category_id' do match ':id' => 'pages#show', :as => :public_page root :to => 'categories#show', :as => :public_category end root :to => 'pages#index', :as => :locale end root :to => 'main#pick_locale'
