Ruby on rails 调用浅嵌套路径:post\U up\U vote\U path(post)失败
前面,为了简化路径调用,我更改了routes.rb文件,以以下方式实现浅嵌套:Ruby on rails 调用浅嵌套路径:post\U up\U vote\U path(post)失败,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,前面,为了简化路径调用,我更改了routes.rb文件,以以下方式实现浅嵌套: SampleApp::Application.routes.draw do get "comments/create" devise_for :users resources :users, only: [:update] resources :topics do resources :posts, except: [:index] end resources :posts, o
SampleApp::Application.routes.draw do
get "comments/create"
devise_for :users
resources :users, only: [:update]
resources :topics do
resources :posts, except: [:index]
end
resources :posts, only: [] do
resources :comments, only: [:create, :destroy]
end
post '/up-vote' => 'votes#up_vote', as: :up_vote
post '/down-vote' => 'votes#down_vote', as: :down_vote
get 'about' => 'welcome#about'
root to: 'welcome#index'
end
但是,当我在分部中调用post\u up\u vote\u pathpost时,它无法识别路径方法:
<div class='vote-arrows'>
<div class='pull-left'>
<div><%= link_to " ", post_up_vote_path(post), class: 'glyphicon glyphicon-chevron-up', method: :post %></div>
<div><strong><%= post.points %></strong></div>
<div><%= link_to " ", post_down_vote_path(post), class: 'glyphicon glyphicon-chevron-down', method: :post %></div>
</div>
</div>
我在show视图中调用上述部分_vote.html.erb:
<div class="row">
<div class="col-md-8">
<%= render partial: 'votes/voter', locals: {post: @post} %>
...
此代码中是否有显示错误的内容?您的路线不正确-您将它们命名为“向下”和“向上”投票,而不是“向下”和“向上”投票 如果您检查rake路由的输出,它将告诉您应该使用什么名称