Rails 3 路由:控制器规范与成员路由不匹配

发布于 2025-01-03 12:58:50 字数 778 浏览 0 评论 0原文

我正在尝试为成员控制器操作编写一个规范,该操作假设指向“/admin/projects/:id/some_action”,routes.rb 文件具有以下内容:

namespace :admin do
  resources :projects do
    member do
      get :some_action
    end
  end
end

因此,当我运行 $ rake paths 时,我得到了正确的 url /admin/projects/:id/some_action,但在控制器规范中我遇到了一个该死的错误。

describe Admin::ProjectsController do
  it "should get the action" do
    project = mock_model(:project, :id => 1)
    get :some_action, {:id => project.id}
  end
end

结果总是一样的:

Failure/Error: get :some_action, {:id => 1}
 ActionController::RoutingError:
   No route matches {:id=>1, :controller=>"admin/projects", :action=>"some_action"}

有人遇到过这种问题吗?有什么建议可以解决吗?

我真的很感谢任何帮助,谢谢!

I'm trying to write a spec to a member controller action that suppose to points to "/admin/projects/:id/some_action", the routes.rb file has the following content:

namespace :admin do
  resources :projects do
    member do
      get :some_action
    end
  end
end

So, when I run $ rake routes I got the right url /admin/projects/:id/some_action, but in the controller spec I got a dammed error.

describe Admin::ProjectsController do
  it "should get the action" do
    project = mock_model(:project, :id => 1)
    get :some_action, {:id => project.id}
  end
end

The result is always the same:

Failure/Error: get :some_action, {:id => 1}
 ActionController::RoutingError:
   No route matches {:id=>1, :controller=>"admin/projects", :action=>"some_action"}

Someone pass through this kind of problem? Any suggestion to solve it?

I really appreciate any help, thanks!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文