En utilisant has_many => grâce à l'association.L'utilisation a beaucoup: à travers
Voici ce que j'ai.
: modèle de planification
has_many :acttypes
has_many :actcategories
has_many :acts, :through => :actcategories
: actes modèle
belongs_to :acttype
has_many :actcategories
has_many :plannings, :through => :actcategories
: modèle actcategories
named_scope :theacts, lambda { |my_id|
{:conditions => ['planning_id = ?', my_id] }}
belongs_to :act
belongs_to :planning
: modèle acttype
has_many :acts
Mon problème Commence ici. Je dois montrer tous les actes par chaque loi type de Plannings qui fait partie de l'association de actcategories En ce moment, je reçois tous les actes et disparus l'association de actcategories.
Contrôleur de planification
def show
@planning = Planning.find(params[:id])
@acttypes = Acttype.find(:all, :include => :acts)
@acts = Actcategory.theacts(@planning)
end
Planning Afficher la vue
<% @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 -%>
Merci pour toute aide.