関連付けによる 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 アソシエーションの一部である計画から各アクト タイプごとにすべてのアクトを表示する必要があり ます。
プランニング コントローラー
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 -%>
助けてくれてありがとう。