Rails功能测试问题

发布于 2024-10-11 18:37:40 字数 870 浏览 5 评论 0原文

当我

get :inside, :format => :xml, :lat2 => "41", :lng2 => "-73.9", :lat1 => "40", :lng1 => "-74", :category => "girl", :order => "date"

使用我的routes.rb 时,包括:

get 'images/inside/:lat1/:lng1/:lat2/:lng2/:order/:category', :to => "images#inside"

我得到

ActionController::RoutingError: No route matches {:lng1=>"-74", :category=>"girl", :lat2=>"41", :format=>:xml, :lng2=>"-73.9", :order=>"date", :lat1=>"40", :action=>"inside", :controller=>"images"}

但是当我这样做时

get :inside, :format => :xml, :lat2 => "41", :lng2 => "-73", :lat1 => "40", :lng1 => "-74", :category => "girl", :order => "date"

它起作用了!

唯一的区别是 lng2 的十进制值。

请注意,如果routes.rb没有参数,它可以工作,但我需要那些

When I do

get :inside, :format => :xml, :lat2 => "41", :lng2 => "-73.9", :lat1 => "40", :lng1 => "-74", :category => "girl", :order => "date"

with my routes.rb includes:

get 'images/inside/:lat1/:lng1/:lat2/:lng2/:order/:category', :to => "images#inside"

I get

ActionController::RoutingError: No route matches {:lng1=>"-74", :category=>"girl", :lat2=>"41", :format=>:xml, :lng2=>"-73.9", :order=>"date", :lat1=>"40", :action=>"inside", :controller=>"images"}

But when I do

get :inside, :format => :xml, :lat2 => "41", :lng2 => "-73", :lat1 => "40", :lng1 => "-74", :category => "girl", :order => "date"

it works!

The only difference is the decimal value of lng2.

Note that if routes.rb has no params, it works, but I need those

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮萍、无处依 2024-10-18 18:37:40

据我所知,这是因为你的价值有一个时期。默认情况下,Rails(至少 Rails3)路由不能包含句点。要解决此问题,请参阅 http://avdi.org/devblog/2010/06/18/rails-3-resource-routes-with-dots-or-如何让 ruby​​ 开发人员变得有点疯狂/

As far as I can tell, it's because your value has a period. By default, Rails (at least Rails3) routes cannot contain periods. To work around this, see http://avdi.org/devblog/2010/06/18/rails-3-resource-routes-with-dots-or-how-to-make-a-ruby-developer-go-a-little-bit-insane/

梦途 2024-10-18 18:37:40

我敢打赌小数点会让 Rails 认为有指定的格式(例如 .xml 或 .js)。

您也许可以使用正则表达式来解决它,类似于此处描述的内容: http://zargony.com/2009/05/05/routing-parameters-with-a-dot

I bet the decimal point is making Rails think that there's a format being specified (e.g. .xml or .js).

You might be able to get around it using a regex, something like what's described here: http://zargony.com/2009/05/05/routing-parameters-with-a-dot

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文