Upvote / Downvote acts_as_votable gemfile Rails错误

时间:2017-04-24 02:54:20

标签: ruby-on-rails ruby rubygems

我在Gemfile中安装了一个gem:

gem 'acts_as_votable', '~> 0.10.0'

我一直收到这个错误:

/User/Name/seminar/project/config/routes.rb:11: syntax error, unexpected tIDENTIFIER, expecting keyword_end put "like" to: "reviews#upvote" ^

我不确定我做错了什么或我目前在我的代码中有什么,但我已经在youtube上遵循了一个基本的教程,但继续得到错误。

这是controller.rb中的代码:

def upvote
  @review= Review.find(params[:id])
  @review.upvote_by current_user
  redirect_to :back
end

这是routes.rb中的代码:

resources :reviews do
  member do
    put "like" to: "reviews#upvote"
  end
end

这是我review.rb的代码:

class Review < ApplicationRecord
  acts_as_votable
  belongs_to :user
end

1 个答案:

答案 0 :(得分:0)

您错过,/中的routes.rb,与此错误无关,但会产生另一个错误。试试这个:

# routes.rb

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