加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 04:22:35 所属栏目:百科 来源:网络整理
导读:在我的rails应用程序中,我有一个团队模型.我的团队的route.rb文件如下所示: resources :teams 在我的teams_controller.rb文件中,team_path(Team.first.id)行正常工作但是我的模型team.rb中无法识别team_path url帮助器.我收到此错误消息: undefined local
在我的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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读