我的应用程序正在通过路径助手调用资源 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/