【发布时间】:2012-02-06 03:48:55
【问题描述】:
我正在尝试覆盖 forem gem 的模型,以便我可以使用 thumbs_up gem 进行投票。
我做了一个rails g模型post,试图通过这行代码继承forem的post模型
class Post < Forem::Post
acts_as_voteable
end
控制器也一样
class PostsController < Forem::Postscontroller
def vote_up
begin
current_user.vote_for(@post = Post.find(params[:id]))
render :nothing => true, :status => 200
rescue ActiveRecord::RecordInvalid
render :nothing => true, :status => 404
end
end
end
我一直收到这个错误
未定义的方法`vote_up_post_path'
在我的 route.rb 中
mount Forem::Engine, :at => "/forums"
resources :posts do
member do
post :vote_up
end
end
我想我在这里做了一些非常愚蠢的事情,而且我没有正确地覆盖模型。我正在使用这个Clarification on how to use "thumbs_up" voting gem with Rails 3 帖子来设置thumbs_up
有人可以帮忙吗?
【问题讨论】:
-
路径方法是从routes.rb生成的。您是否有用于 vote_up 操作的路线?
-
@patrickmcgraw 我已经用路线信息更新了问题,请看一下
-
好的,那么当你运行 rake 路由时你会得到什么?
-
@patrickmcgraw vote_up_post POST /posts/:id/vote_up(.:format) {:action=>"vote_up", :controller=>"posts"}
-
那一切看起来都很好。未定义的方法异常究竟是在哪里引发的?
标签: ruby-on-rails model vote-up-buttons