的link_to问题继承的Active Record类 [英] link_to issue with inherited Active Record class
本文介绍了的link_to问题继承的Active Record类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是类,因为我让他们设置了:
Here are the classes as I have them set up:
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
有关的统计控制器index操作:
For the Stats Controller index action:
def index
@stats = Stat.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @stat }
end
end
在索引视图的统计数据存在的code此位:
In the index view for stats there is this bit of code:
<% @stats.each do |stat| %>
...
<td><%= link_to 'Show', stat %></td>
<% end %>
和我得到这个错误:
undefined method `total_stat_path' for #<ActionView::Base:0x0000010324c1f8>
为什么不能在这里的的link_to工作?我是否需要创建一个单独的控制器来处理 TotalStat
?
推荐答案
有明确的STI(单表继承)问题上都存在,但我需要看到更多的code,看看什么是真正起来。一个快速的解决将是更具体有关的link_to路径:
There's clearly an STI(single table inheritance) issue there, though I'd need to see more code to see what's really up. A quick fix would be to be more specific about the link_to path:
<%= link_to "Show", stat_path(stat) %>
这篇关于的link_to问题继承的Active Record类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文