views:

50

answers:

1

I'm having a couple issues with Rails 3 routing, and I just can't fathom why things aren't working.

For instance, I have a functional test that includes:

assert_routing("/store/users/[email protected]/license/ch7bHtrx",
               {:controller => 'store/users', :action => 'license', :email => '[email protected]', :id => 'ch7bHtrx' })

which produces

ActionController::RoutingError: No route matches {:controller=>"store/users", :email=>"[email protected]", :id=>"ch7bHtrx", :action=>"license"}
/test/functional/store/users_controller_test.rb:32:in `test_should_get_license_download'

which is interesting because it actually works in the path to controller direction, routes.rb includes

namespace :store do
  controller :users do
    get 'users/:email/license/:id' => :license, :email => VALID_EMAIL_REGEX_FOR_ROUTE, :as => :license_download
  end
end

and rake routes produces

store_license_download GET    /store/users/:email/license/:id(.:format)   {:action=>"license", :controller=>"store/users", :email=>/([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)/i}

I'm a relative Rails newbie, so I don't feel qualified to say that something's buggy, but I simply can't come up with any explanation that rake routes would have those entries, yet would fail to actually route that way.

Any help would be greatly appreciated.

Edit: Removed an example issue that ended up being a bug in form_for confusing the routing system with conflicting information.

A: 

I usually use resource routes, but I think the rules are the same for old style. Url you put inside the block are appended. So
namespace :store do
controller :users do
get 'action' => :action
end
end
becomes '/store/users/action' mapped to :action inside users_controller.

Art Shayderov
That's not what rake route says, and the test works great for url to action mapping. If I drop the '/users' prefix, then the url to action mapping starts failing too. So I don't think that the 'controller' keyword works the same as 'resources' in that respect.
bdrister