From: serbulentunsal@... Date: 2005-12-18T04:42:46+09:00 Subject: Passing multiple parameters with select-option to controller Hi all, I'm using Windows Xp, Mysql 5, Webrick, Rails 1.0 I've 3 tables which have HABTM relationship. My tables names are all set to uncountble. Name of tabels are anabilimdali (includes department info id name etc.), ogretimuye (personel information like id , name , dept. ) yayin (document information), and for relationships yayin_anabilimdali , yayin_ogretimuye . The relationship between yayin_anabilimdali is ok. But i can't write any parameters to yayin_ogretimuye table when I try to create new yayin object. The object was successfully creted in yayin table and the relationship was successfully created in yayin_anabilimdali table. Here is the codes; model yayin.rb class Yayin < ActiveRecord::Base has_and_belongs_to_many :ogretimuye has_and_belongs_to_many :anabilimdali end controller yayin_controller.rb class YayinController < ApplicationController model :yayin ..... ..... def new @anabilimdali = Anabilimdali.find (:all , :order => "ad") @ogretimuye = Ogretimuye.find (:all , :order => "ad") end def create @anabilimdali = Anabilimdali.find_all @ogretimuye = Ogretimuye.find_all item = Yayin.new item.attributes = @params["yayin"] if item.save for anabilimdali in @anabilimdali if (@params[anabilimdali.ad]) item.anabilimdali<<(anabilimdali) end end for ogretimuye in @ogretimuye if (@params[ogretimuye[ogretimuye.id] == ogretimuye.id ) item.ogretimuye<<(ogretimuye) end end redirect_to(:action => "list") else render_text "Couldn't add new item" end end .... .... View new.rhtml
<% for @anabilimdali in @anabilimdali %>
<%= @anabilimdali.ad %> :
<% end %>
<%for ogretimuye in @ogretimuye%>