Hi there,
I' have three tables: chiratfilm | chiratfonction | chiratpersonne.
my models are:
class tfilm < ActiveRecord::Base
has_many :film_fonctions, :dependent => :destroy
has_many :fonctions, :through => :tfilm_fonctions
has_many :film_personnages, :dependent => :destroy
has_many :personnages, :through => :film_personnages
end
-----
class fonction < ActiveRecord::Base
has_many :film_fonctions, :dependent => :destroy
has_many :films, :through => :film_fonctions
has_many :fonction_personnages, :dependent => :destroy
has_many :personnages, :through => :fonction_personnages
end
-----
class personnage < ActiveRecord::Base
has_many :fonction_personnages, :dependent => :destroy
has_many :fonctions, :through => :fonction_personnages
has_many :film_personnages, :dependent => :destroy
has_many :films, :through => :film_personnages
end
----
well, my problem is, in a form view for my film i want to choose many fonction and i also want to choose many personne depedent of fonction.
for example, i have this form view for a new or edit film:
<% for fonction in Fonction.find(:all, :order =>'titre ASC' ) %>
<div>
<%= check_box_tag "film[fonction_ids][]", fonction.id, @film.fonctions.include?(fonction) %>
<%= link_to_function(fonction.titre) do |page|
page.visual_effect :toggle_blind, "#{fonction.id}"
end
%>
<hr size="1" width="100%" align="left" border="dotted"/>
</div>
<div id="<%= fonction.id %>" style="display:none;" >
<div id="perso">
<% for personnage in Personnage.find(:all, :order =>'titre ASC' ) %>
<div>
<%= check_box_tag "film[personnage_ids][]", personnage.id, @film.personnages.include?(personnage) %>
<%= personnage.titre %>
<hr size="1" width="100%" align="left" border="dotted"/>
</div>
<% end -%>
</div>
</div>
<% end -%>
and my controller for the film
def create
@film = Film.new(params[:film])
respond_to do |format|
if @film.save
flash[:notice] = 'film was successfully created.'
format.html { redirect_to admin_films_url }
format.xml { render ml => @film, :status => :created, :location => @film }
else
format.html { render :action => "new" }
format.xml { render ml => @film.errors, :status => :unprocessable_entity }
end
end
end
def update
params[:chiratfilm][:chiratfonction_ids] ||=[]
params[:chiratfilm][:chiratpersonnage_ids] ||=[]
@film = film.find(params[:id])
respond_to do |format|
if @film.update_attributes(params[:film])
flash[:notice] = 'film was successfully updated.'
format.html { redirect_to admin_films_url }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render ml => @film.errors, :status => :unprocessable_entity }
end
end
end
actually i can record a film with many fonctions but not many personnage for many function into the film.
so i want 1 film with many fonctions and those many fonctions have diferent many personnages…
any idea ?
pleeeeeaaassseee !!!!
thanks !
kinggordo
am i clear ?
Partager