Использование has_many => через объединение.Использование имеет много: через
Вот что у меня есть.
: планирование модели
has_many :acttypes
has_many :actcategories
has_many :acts, :through => :actcategories
: действует модель
belongs_to :acttype
has_many :actcategories
has_many :plannings, :through => :actcategories
: actcategories модель
named_scope :theacts, lambda { |my_id|
{:conditions => ['planning_id = ?', my_id] }}
belongs_to :act
belongs_to :planning
: acttype модель
has_many :acts
Моя проблема начинается здесь. Мне нужно, чтобы показать все Деяния каждого типЗакона от планировок, который является частью actcategories ассоциации Сейчас я получаю все акты и отсутствующие actcategories ассоциации.
Контроллер планирования
def show
@planning = Planning.find(params[:id])
@acttypes = Acttype.find(:all, :include => :acts)
@acts = Actcategory.theacts(@planning)
end
Планирование Показать Просмотр
<% @acttypes.each do |acttype|%>
<%= acttype.name %>
<% @acts.each do |acts| %>
<li><%= link_to acts.act.name, myacts_path(acts.act, :planning => @planning.id) %></li>
<% end %>
<% end -%>
Спасибо за любую помощь.