has_many => 연결을 사용합니다.많이 사용함 : through
내가 가진 것은 다음과 같습니다.
: 계획 모델
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 협회 의 일부입니다 Plannings에서 각 행위 유형 모든 행를 표시해야합니다. 어떤 도움
계획 컨트롤러
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 -%>
감사합니다.