“没有路由匹配"在 Rails 3 中使用 current_page 时 [英] "No routes matches" when using current_page in Rails 3

查看:35
本文介绍了“没有路由匹配"在 Rails 3 中使用 current_page 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人在使用 current_page 时遇到过路由神秘地变得无法检测到的情况?在 Rails 3 中?即使完全生成的脚手架包含路由、视图和控制器,我也会收到没有路由匹配"错误.

Has anybody experienced routes mysteriously becoming undetectable when using current_page? in Rails 3? Even with a fully generated scaffold complete with routes, a view, and a controller, I am getting a "No route matches" error.

代码如下:

if current_page?(:controller => 'users', :action => "show")

如果我向 routes.rb 添加匹配"命令,它可以正常工作,但是如果资源已经创建,我为什么还需要这样做?我错过了什么?

If I add a "match" command to routes.rb, it works fine, but why would I need to do that if the resources have already been created? What am I missing?

推荐答案

您缺少这个助手的 id 参数:

You're missing the id parameter from this helper:

current_page?(:controller => "users", :action => "show", :id => "1")

它希望您通过完整的路线.如果您不想要这个并且只想匹配控制器和动作,那么我建议您自己编写代码.

It expects you to pass a full route through. If you don't want this and only want to match on the controller and action then I would recommend coding your own.

这篇关于“没有路由匹配"在 Rails 3 中使用 current_page 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆