ruby-on-rails - Rails 无法识别路径

标签 ruby-on-rails ruby-on-rails-4 path routes

我的应用程序正在通过路径助手调用资源 show_popular_hashtags_path ,但 Rails 似乎不认识它。这是我的部分:

.col-xs-12.no-padding.blue-title{style: "page-break-inside: avoid !important;"}
  .col-xs-12.text-center.global-map.no-padding
    %h1 
      = t('uniq.hashtag.title')
    .js-column-chart-hashtags{data: {url: show_popular_hashtags_path(id: @project.id, provider: provider), provider: provider}}
      .column-chart-hashtags.statistics-chart{class: "#{provider}", style: "width: 100%"}
    %h2.empty-message.column-chart-hashtags{class: "#{provider}", style: "padding-top: 15px; padding-bottom: 30px; display: none;"}
      = t('unique.there_is_no_info') 

这是我的routes.rb :

namespace :user do
  resources :projects, except: [:delete] do
    member do
      get :show_users, to: 'projects#js_show_users_data', as: :show_users_data
      get :show_popular_hashtags, to: 'projects#js_show_popular_hashtags', as: :show_popular_hashtags
      get :show_activity_data, to: 'projects#js_show_activity_data', as: :show_activity_data

对于另一条路线,一切都进展顺利,即使我运行 rake routes | grep show_popular_hashtags ,输出为:

$ rake routes | grep show_popular_hashtags
    show_popular_hashtags_user_project GET      /user/projects/:id/show_popular_hashtags(.:format)       user/projects#js_show_popular_hashtags

所以,这看起来路线很好,但是当我访问包含部分的 View 时,会出现此错误:

undefined method `show_popular_hashtags_path' for #<#<Class:0x007fa20d865d10>:0x007fa20dc5a6f0>

我已经重新启动了服务器,但它不起作用。

最佳答案

您的路由助手的名称实际上是 show_popular_hashtags_user_project,而不是 show_popular_hashtags。您可以在rake paths输出的第一列中看到它:

$ rake routes | grep show_popular_hashtags
    show_popular_hashtags_user_project GET      /user/projects/:id/show_popular_hashtags(.:format)       user/projects#js_show_popular_hashtags

只需在 View 中将 show_popular_hashtags 路由助手的名称更改为 show_popular_hashtags_user_project 即可。

关于ruby-on-rails - Rails 无法识别路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37245020/

相关文章:

javascript - jQuery Accordion 打开后立即关闭

ruby-on-rails - 在付款请求中的何处添加 3DS 参数

启动 Firefox 时出现 python webdriver 错误

path - 使用装饰器在 Python 中行走路径

ruby-on-rails - psych.rb :370 中的 Rails 服务器错误

ruby-on-rails - 将数据库模型转换为 Ruby On Rails 上的模型

ruby-on-rails - 使用 ActiveSupport::Concern 的 Rails mixin 不起作用

java - 如何获取我正在运行的 jar 文件所在目录的路径?

ruby-on-rails - 嵌套资源的 URL 段

string - rails4//pluralize 当计数为 0 时进行复数化