Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails嵌套模型get字段_Ruby On Rails_Ruby_Activerecord - Fatal编程技术网

Ruby on rails Rails嵌套模型get字段

Ruby on rails Rails嵌套模型get字段,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,在我的应用程序中,我有这样的模型结构: class Organization < ActiveRecord::Base belongs_to :organization_type has_many :organization_type_links, :dependent => :destroy end class OrganizationType < ActiveRecord::Base has_many :organizations has_many :or

在我的应用程序中,我有这样的模型结构:

class Organization < ActiveRecord::Base
  belongs_to :organization_type
  has_many :organization_type_links, :dependent => :destroy
end

class OrganizationType < ActiveRecord::Base
  has_many :organizations
  has_many :organization_type_links
end

class OrganizationTypeLink < ActiveRecord::Base
  belongs_to :organization
  belongs_to :organization_type
end
所以OrganizationTypeLink是一个链接表,如何通过它获取OrganizationType.t_name

就像我写的:

=@organization.organization\u type\u links.t\u name

是真的吗?如何纠正呢

@organization.organization\u type\u links是一个数组。请尝试以下操作以调用组织类型上的t_name方法:


这将返回一个数组,该数组包含任何tu name返回的内容。

这就是数组。。。如何在没有[]的情况下为视图设置样式?类似于[1,2,3,4]。to_句子:last_word_connector=>and?返回1、2、3和4,或者可能是[1、2、3、4]。join,=>1、2、3、4?
@organization.organization_type_links.collect{|link| link.organization_type.t_name}