2012-01-09 106 views
1

我想重載一個forem gem模型,以便我可以使用thumbs_up gem進行投票。覆蓋模型導軌3.1

我做了一個軌道G系列車型後,並試圖通過這一行代碼

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

有人可以幫忙嗎?

+0

路徑方法從routes.rb生成。你有沒有參加vote_up動作的路線? – patrickmcgraw 2012-01-09 16:09:25

+0

@patrickmcgraw我更新了路線信息的問題請看看 – 2012-01-09 16:12:26

+0

好的,那麼當你運行耙路線時你會得到什麼? – patrickmcgraw 2012-01-09 16:18:08

回答

1

看來這是一個愚蠢的錯誤,在與patrickmcgraw討論時意識到它。

FOREM隱藏你的路線,和你有路線之前提到main_app,所以寫的

main_app.vote_up_post_path代替vote_up_post_path後的頁面再次。

希望它可以幫助有人試圖使用forem。

3

如果我正確地得到您的問題,您想改變forem Post的行爲以支持使用acts_as_votable進行投票。 對於工作,你需要重新打開FOREM :: Post類在初始化(例如配置/初始化/ forem.rb),並添加到它acts_as_votable一行:

module Forem 
    class Post 
    acts_as_votable 
    end 
end 

與同爲培訓就業部:: PostsController:

module Forem 
    class 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 
end 
+0

究竟應該把這個代碼?因爲如果我把它放入初始化程序即config/initializers/forem.rb。我的道路本身變得無法辨認 – 2012-01-09 16:52:33