我的应用程序正在调用资源问题路径助手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
所以,这看起来路线很好,但是当我访问包含部分的视图时,会出现此错误:
undefined method `show_popular_hashtags_path' for #<#<Class:0x007fa20d865d10>:0x007fa20dc5a6f0>
我已经重新启动了服务器,但它没有用。
答案 0 :(得分:2)
路线助手的名称实际上是show_popular_hashtags_user_project
,而不是show_popular_hashtags
。您可以在rake routes
输出的第一列中看到它:
$ 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
只需在视图中将show_popular_hashtags
路线助手的名称更改为show_popular_hashtags_user_project
即可。