开发者

Rails 3 routing failures

开发者 https://www.devze.com 2023-01-19 19:14 出处:网络
I\'m having a couple issues with Rails 3 routing, and I just can\'t fathom why things aren\'t working.

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/me@here.com/license/ch7bHtrx",
               {:controller => 'store/users', :action => 'license', :email => 'me@here.com', :id => 'ch7bHtrx' })

which produces

ActionController::RoutingError: No route matches {:controller=>"store/users", :email=>"me@here.com", :id=>"ch7bHtrx", :action=>"license"}
/test/functional/store/users_controller_test.rb:32:in `test_should_get_license_downlo开发者_运维知识库ad'

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号