我的评论投票方法有问题。我是 RoR 的初学者,正在等待您的建议。
我得到的错误是:
ActionController::RoutingError at /posts/51f7d1279fefa5405a000003 没有路由匹配 {:controller=>"comments", :action=>"vote(1)", :class=>"post__button--edit"}
我的代码:
评论.rb
class Comment
include Mongoid::Document
field :name, type: String
field :email, type: String
field :body, type: String
field :up_vote, type: Integer, default: "0"
field :down_vote, type: Integer, default: "0"
belongs_to :post
validates_presence_of :name, :email, :body
def self.add_up_vote
self.increment(:up_vote, 1)
end
def self.add_down_vote
self.decrement(:down_vote, 1)
end
end
注释控制器.rb
.
.
.
def vote(a)
@comment = Comment.find(params[:comment_id])
@post = Post.find(params[:post_id])
if a == 1
comment.add_up_vote
redirect_to @post
elsif a == -1
comment.add_down_vote
redirect_to @post
else
redirect_to @post
end
end
路线.rb
Easyblog::Application.routes.draw do
authenticated :user do
root :to => 'home#index'
end
root :to => "home#index"
devise_for :users
resources :users
resources :posts do
resources :comments
member do
post :mark_archived
end
end
end
我在等你的帮助:)