link_to与inheritance的Active Record类发生问题

以下是我设置的类:

class Stat < ActiveRecord::Base belongs_to :stats_parent end class TotalStat < Stat belongs_to :stats_parent end #The StatsParent class is just to show how I use the relation. class StatsParent < ActiveRecord::Base has_one :total_stat has_many :stats end 

对于统计控制器索引操作:

 def index @stats = Stat.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @stat } end end 

在stats的索引视图中有以下代码:

  ...   

我收到这个错误:

 undefined method `total_stat_path' for # 

为什么link_to不能在这里工作? 我是否需要创建一个单独的控制器来处理TotalStat

那里显然存在STI(单表inheritance)问题,但我需要查看更多代码才能看到真正的问题。 快速解决方法是更具体的link_to路径:

 <%= link_to "Show", stat_path(stat) %>