我有一个critical_factor带有一些字段的脚手架(),catalog_table_id还有selectRight其他catalog_table带有字段名称的table_name脚手架() model。
当我在字段中的视图中选择时,填充critical_factor所选表的所有字段。catalog_table_idselectRight
我有一个has_and_belong_to catalog_tables_critical_factors与字段catalog_table_id,critical_factor_id和table_relation_fields_id。在最后一个字段中,我想id从视图selectRight中保存,critical_factor但我只能保存前两个字段。
有任何想法吗?
关键因素模型
class CriticalFactor < ActiveRecord::Base
has_and_belongs_to_many :catalog_tables
attr_accessible: :critical_factor_id,:selectRight, :catalog_table_id
def selectRight=(options)
self.catalog_tables.clear
options.each do |option|
unless option.empty?
line = CatalogTable.find(catalog_table_id)
modelo = line.model
case modelo
when 'ActivityTypes'
line = ActivityType.find(options,options.id)
when 'Programs'
line = Program.find(options)
end
self.catalog_tables << line
end
end
end
目录表模型
class CatalogTable < ActiveRecord::Base
has_and_belongs_to_many :critical_factors
attr_accessible :name, :model, :table
end
catalog_table_critical_factor 模型
class CatalogTablesCriticalFactor < ActiveRecord::Base
attr_accessible :critical_factor_id, :catalog_table_id, :table_select_field_id
end