2015-06-22 60 views
2

我要將投票系統添加到我的rails應用程序,並嘗試使用activerecord-reputation-system gem運行信譽系統,其次是railscasts #364視頻。路由錯誤 - 沒有路由匹配使用activerecord-reputation-system gem in rails的[GET]錯誤

我掙扎在路由錯誤,當我點擊給予好評或downvote,它顯示了一個錯誤「無路由匹配[GET] 「/俳句/ 1 /票」

enter image description here enter image description here

/config/routes.rb:

Youhaiku::Application.routes.draw do 
    get 'signup', to: 'users#new', as: 'signup' 
    get 'login', to: 'sessions#new', as: 'login' 
    get 'logout', to: 'sessions#destroy', as: 'logout' 

    resources :users 
    resources :sessions 
    resources :haikus do 
    member { post :vote } 
    end 

    root to: 'haikus#index' 
end 

/app/controllers/haikus_controller.rb:

def vote 
    value = params[:type] == "up" ? 1 : -1 
    @haiku = Haiku.find(params[:id]) 
    @haiku.add_evaluation(:votes, value, current_user) 
    redirect_to :back, notice: "Thank you for voting!" 
end 

/app/views/haikus/_haiku.html.erb:

<div class="haiku"> 
    <%= simple_format haiku.content %> 
    <em> 
    -- <%= haiku.user.name %> 
    | <%= link_to "up", vote_haiku_path(haiku, type: "up"), method: "post" %> 
    | <%= link_to "down", vote_haiku_path(haiku, type: "down"), method: "post" %> 
    </em> 
</div> 

我檢查了這個issue但這不是幫助我。所以,我真的需要幫助。

+0

試試這個'<%​​= link_to「up」,vote_haiku_path(ha句,類型:「up」),方法:: post%>' –

+0

是的,我已經嘗試過了,但它不適合我! – diya

+0

你能否粘貼你在呈現這個鏈接後得到的html。 –

回答

0

從您收到的錯誤中可以看出,您正在發送GET請求,並且Rails正在等待此操作的POST。您需要確保您使用link_to生成了正確的HTML。

爲了達到這個目的,請檢查您的鏈接上的data-method是否顯示「帖子」。要做到這一點,你可以右鍵單擊向上/向下投票鏈接,然後按檢查元素。

如果它不存在但您的視圖部分說method: "post"嘗試將其更改爲method: :post Pardeep在評論中建議。

+0

即使這是行不通的'">' –

+0

是的,即使上面的一個不適合我。 – diya

+0

請讓我們知道您在HTML獲取頁 – Glupo

相關問題