充当可投票的路由错误 [英] Acts as votable routing error

查看:36
本文介绍了充当可投票的路由错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将行为用作可投票的宝石,但无法理解它的实际工作原理.我找不到任何好的解决方法或教程.我尝试实施此处提到的已接受解决方案,但遇到了路由错误.任何人都可以通过一个好的教程来帮助我,或者指出如何编辑以下代码使其工作.

I'm trying to use acts as votable gem and can't understand how it actually works. I couldn't find any good workarounds or tutorials for it. I tried implementing the accepted solution mentioned here but got Routing Error. Can anyone help me out with a good tutorial or point me out how to get it to work editing the following code.

routes.rb

resources :posts do
  member do
    put "like", to: "posts#upvote"
  end
end

帖子控制器

def upvote
  @post = Post.find(params[:id])
  @post.liked_by current_user
  redirect_to @post
end

show.html.erb

show.html.erb

<%= link_to "Bookmark Post", like_post_path(@post, method: :put), class: "button tiny" %>

推荐答案

method 属性应该传递给 link_to 方法,而不是路径助手,像这样

method attribute should be passed to the link_to method, not the path helper, like this

<%= link_to "Bookmark Post", like_post_path(@post), method: :put, class: "button tiny" %>

这篇关于充当可投票的路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆