【发布时间】:2013-10-24 05:53:24
【问题描述】:
我对acts_as_votable gem 有疑问。我有一个简单的论坛应用程序,我希望有功能来对帖子进行投票。我用于这个acts_as_votable gem。我在帖子控制器中添加了两种方法:
def upvote
@post = post.find(params[:id])
@post.liked_by current_user
redirect_to forum_topic_path(@post.topic.forum, @post.topic)
end
def downvote
@post = post.find(params[:id])
@post.downvote_from current_user
redirect_to forum_topic_path(@post.topic.forum, @post.topic)
end
我的路线是:
resources :topics, except: :index do
resources :posts do
member do
put "like", to: "posts#upvote"
put "dislike", to: "posts#downvote"
end
end
end
在我的主题显示操作视图中,我有以下链接:
= link_to "Upvote", like_topic_post_path(post.topic.id,post.id, method: :put)
= link_to "Downvote", dislike_topic_post_path(post.topic.id,post.id, method: :put)
当我尝试点击upvote 或downvote 时,我被重定向到:
http://localhost:3000/topics/104/posts/55/like?method=put 我有以下错误:
没有路线匹配 [GET] "/topics/104/posts/55/like"
怎么了?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4