2012-05-24 46 views
1

我試圖將thumbs_up gem實現到我的應用中,即使我有路由對於vote_up行動沒有路由匹配{:action =>「vote_up」,:controller =>「posts」} thumbs_up的錯誤

我的帖子控制器看起來像

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 

我的路線看起來像

resources :posts do 
    get :vote_up, :on => :member 
    resources :comments 
    end 

我不知道是什麼問題,如果有人可以幫助我,或指向我一個教程使用會很棒的thumbs_up寶石。

+0

你能分享你的視圖代碼嗎? – rb512

+0

'current_user.vote_for(@post = Post.find(params [:id]))'。恕我直言,作爲一種方法的參數也是不好的編程習慣。 – tokland

回答

2

問題是您要求vote_up沒有一個職位的ID。只是看你的控制器:

current_user.vote_for(@post = Post.find(params[:id]))

然而,我沒有看到你的要求任何id場。問題在於你的看法。

+0

同意。 'vote_up'路由在成員資源上。錯誤是因爲你沒有將'id'參數傳遞給這條路線。 –

+0

@Jordan比例:修正後的代碼應該是什麼樣子?你如何將id放入請求中? – gbutters

相關問題