I have an scaffold (critical_factor
) with some fields like catalog_table_id
and selectRight
and also other scaffold (catalog_table
) with the fields name table_name
, model
.
When I select in the critical_factor
view in the field catalog_table_id
the selectRight
fill with all the fields of the table selected.
I have a has_and_belong_to catalog_tables_critical_factors
with the fields catalog_table_id
, critical_factor_id
and table_relation_fields_id
. In the last field I want save the id
from the selectRight
in the critical_factor
view but I am only able to save the first two fields.
Any ideas?
Critical Factor Model
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
Catalog Table Model
class CatalogTable < ActiveRecord::Base
has_and_belongs_to_many :critical_factors
attr_accessible :name, :model, :table
end
catalog_table_critical_factor model
class CatalogTablesCriticalFactor < ActiveRecord::Base
attr_accessible :critical_factor_id, :catalog_table_id, :table_select_field_id
end