Witam,
Jestem początkującym w ror. Mój problem dotyczy tablicy złączeniowej.
[code] Modele:
class StatisticalControl < ActiveRecord::Base
has_many :statistical_control_parts
belongs_to :type
end
class StatisticalControlPart < ActiveRecord::Base
belongs_to :statistical_control
belongs_to :part
end
class Part < ActiveRecord::Base
has_many :statistical_control_parts
has_and_belongs_to_many :types
end
class Type < ActiveRecord::Base
has_one :statistical_controls
has_and_belongs_to_many :parts
end
Kontrolery:
class StatisticalControlController < ApplicationController
before_filter :login_required
layout “pms”
active_scaffold :statistical_control do |config|
config.columns = [
…
]
config.list.columns.exclude :statistical_control_parts
config.create.columns.exclude :statistical_control_parts
config.update.columns.exclude :statistical_control_parts
config.nested.add_link “Part”, [:statistical_control_parts]
end
end
class StatisticalControlPartController < ApplicationController
active_scaffold
end
class Part < ApplicationController
active_scaffold
end
class Type < ApplicationController
active_scaffold
end[/code]
Tablica StatisticalControls ma klucz obcy: type_id,
tablica StatisticalControlParts ma klucze obce: statistical_control_id, part_id,
oraz tablica złączeniowa PartsTypes: part_id, type_id.
Do tablicy PartsTypes wprowadziłem przykładowe dane.
Z kontrolera StatisticalControlPart wyświetlam listę Parts’ów - wyświetla się pełna zawartość tabeli Parts a ja chciałbym zawęzić ją tylko do tych Parts’ów które należą do aktualnego type_id (połączenie jest zdefiniowane w tablicy PartsTypes). Co muszę dopisać i w którym kontrolerze?
Uff! Mam nadzieję, że wyjaśniłem to w miarę jasno 