我对我的应用程序有投票功能,但无法返回到应用投票的同一页面。我知道我必须填写link_to方法,但我对路由/ ruby语法的理解有点有限,所以我甚至不确定[post,vote]是正确的。我觉得我也错过了别的东西。我有没有提供足够的信息?我应该如何处理这个问题?或者更好的是,我怎样才能更好地理解路由?谢谢。Ruby-on-Rails投票部分路由
这里是我得到的错误: No route matches [GET] "/posts/13/up-vote"
我的投票部分:
<% if policy(Vote.new).create? %>
<div class="vote-arrows pull-left">
<div>
<%= link_to [post, vote],
post_up_vote_path(post),
class: "glyphicon glyphicon-chevron-up #{(current_user.voted(post) && current_user.voted(post).up_vote?) ? 'voted' : '' }" %>
</div>
<div>
<strong><%= post.points %></strong>
</div>
<div>
<%= link_to [post, vote],
post_down_vote_path(post),
class: "glyphicon glyphicon-chevron-down #{(current_user.voted(post) && current_user.voted(post).down_vote?) ? 'voted' : '' }" %>
</div>
</div>
<% end %>
我的routes.rb
Bloccit::Application.routes.draw do
devise_for :users
resources :users, only: [:update]
resources :topics do
resources :posts, except: [:index]
end
resources :posts, only: [] do
resources :comments, only: [:create, :destroy]
resources :favorites, only: [:create, :destroy]
post '/up-vote' => 'votes#up_vote', as: :up_vote
post '/down-vote' => 'votes#down_vote', as: :down_vote
end
get 'about' => 'welcome#about'
root to: 'welcome#index'
end
粘贴您的routes.rb –