【发布时间】:2014-06-26 20:33:28
【问题描述】:
所以,事情是这样发展的:
关系:
类型有很多程序, 程序属于一个类型
程序有很多组, 组属于程序
型号:
class Type < ActiveRecord::Base
has_many :programs
end
程序模型:
class Program < ActiveRecord::Base
belongs_to :type
has_many :groups
end
组模型:
class Group < ActiveRecord::Base
belongs_to :program
end
在我看来:
<% @Types.each do |type|%> //this works
//Print some info about type
<%type.programs.each do |program|%> //this also works
//Print some info about this program, which depends of the type above
<%program.groups.each do |group|%> //this doesnt work at all
//Print some info about this group, which depends of the program above
<%end%>
<%end%>
<%end%>
我得到的错误如下:
uninitialized constant Program::Groups
应用跟踪是:
app/views/admin/index.html.erb:33:in `block (2 levels) in _app_views_admin_index_html_erb__4501256709281346516_69833887896820'
app/views/admin/index.html.erb:18:in `block in _app_views_admin_index_html_erb__4501256709281346516_69833887896820'
app/views/admin/index.html.erb:3:in `_app_views_admin_index_html_erb__4501256709281346516_69833887896820'
【问题讨论】:
-
试试 program.groups 而不是 program.group
-
index.html.erb中的哪一行的编号为 33?另外,编辑您的视图代码以修复group错字。 -
,说“//这根本不起作用”的那个n_n
-
所以你在这一行有
<% program.group.each do |group| %>,对吧? -
是的,就是那个
标签: ruby-on-rails join