Ruby on Rails:控制器不评估方法

时间:2016-02-28 13:35:39

标签: ruby-on-rails ruby controller

next comment按钮应指向http://localhost:3000/articles/14/comments/70

目前执行的是: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

更新

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

1 个答案:

答案 0 :(得分:0)

运行rake routes并检查是否有到next_comment_article_comment_path(@article, @comment)

的路线

尝试whith:article_comment_next_comment_path(@article, @comment)