2016-02-28 44 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