2016-02-28 43 views
1

next comment按鈕應指向http://localhost:3000/articles/14/comments/70Ruby on Rails:控制器未評估方法

它目前執行的是:http://localhost:3000/articles/14/comments/56/next_comment

怎樣才能解決這個問題?

#button 
= link_to "next comment", next_comment_article_comment_path(@article, @comment) 

#controller 
class CommentsController < ApplicationController 

    def next_comment 
    @comment ||= @scope.next(@comment) 
    end 

    def scope 
    @scope ||= @article.comments 
    end 
end 

UPDATE

#routes.rb 
resources :articles do 
resources :comments do 
    member do 
    get 'next_comment' 
    end 
end 
end 
+0

你可以更新'routes.rb'代碼的問題? – Pavan

+0

完成!謝謝... – Liroy

+0

任何線索是怎麼回事? – Liroy

回答

0

運行rake routes,並檢查是否有到next_comment_article_comment_path(@article, @comment)

一個途徑,並嘗試蒙山:article_comment_next_comment_path(@article, @comment)

+0

路由本身正在工作,當然在'rake routes'下出現,問題是該方法沒有執行。 – Liroy

+0

mmm ...我不明白你在哪裏調用範圍方法,你正在訪問'@範圍'誰必須是在那一刻nill .. 你爲什麼不這樣做? 'def next_comment; @comment || = scope.next(params [:comment]);結束' 'def scope; @scope || = params [:article] .comments;結束' –

+0

有道理,但我不認爲這就是爲什麼該方法沒有執行。 – Liroy