ruby-on-rails – 在模型中无法识别的rails path helper

在我的rails应用程序中,我有一个团队模型.我的团队的route.rb文件如下所示:
resources :teams

在我的teams_controller.rb文件中,team_path(Team.first.id)行正常工作但是我的模型team.rb中无法识别team_path url帮助器.我收到此错误消息:

undefined local variable or method `team_path' for # <Class:0x00000101705e98>
 from /usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing'

我需要找到一种方法让模型识别team_path路径助手.

解决方法

您应该能够以这种方式调用url_helpers:
Rails.application.routes.url_helpers.team_path(Team.first.id)

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...