# Passing multiple parameters with select-option to controller

**URL:** <https://rubytalk.org/t/passing-multiple-parameters-with-select-option-to-controller/23379>\
**Category:** ruby-talk\
**Created:** [17 December 2005 19:42 UTC](https://rubytalk.org/t/passing-multiple-parameters-with-select-option-to-controller/23379 "2005-12-17T19:42:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serbulentunsal](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Serbulentunsal](https://rubytalk.org/u/Serbulentunsal)\
**Post date:** [17 December 2005 19:42 UTC](https://rubytalk.org/t/passing-multiple-parameters-with-select-option-to-controller/23379/1 "2005-12-17T19:42:46Z")

</div>

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  
&nbsp;&nbsp;&nbsp;&nbsp;@anabilimdali = Anabilimdali.find (:all , :order =\> "ad")  
&nbsp;&nbsp;&nbsp;&nbsp;@ogretimuye = Ogretimuye.find (:all , :order =\> "ad")  
&nbsp;&nbsp;end

def create  
&nbsp;&nbsp;&nbsp;&nbsp;@anabilimdali = Anabilimdali.find\_all  
&nbsp;&nbsp;&nbsp;&nbsp;@ogretimuye = Ogretimuye.find\_all  
&nbsp;&nbsp;&nbsp;&nbsp;item = Yayin.new  
&nbsp;&nbsp;&nbsp;&nbsp;item.attributes = @params["yayin"]

&nbsp;&nbsp;&nbsp;&nbsp;if item.save  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for anabilimdali in @anabilimdali  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (@params[[anabilimdali.ad](http://anabilimdali.ad)])

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.anabilimdali\<\<(anabilimdali)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for ogretimuye in @ogretimuye

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (@params[ogretimuye[[ogretimuye.id](http://ogretimuye.id)] == [ogretimuye.id](http://ogretimuye.id) )

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item.ogretimuye\<\<(ogretimuye)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to(:action =\> "list")  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render\_text "Couldn't add new item"  
&nbsp;&nbsp;&nbsp;&nbsp;end  
end  
....  
....

View

new.rhtml

\<h1\>New yayin\</h1\>

\<%= start\_form\_tag :action =\> 'create' %\>  
&nbsp;&nbsp;\<%= render :partial =\> 'form' %\>

\<p\>\<label for="yayin\_anabilimdali"\>Anabilimdalllari\</label\>\<br /\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% for @anabilimdali in @anabilimdali %\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= @anabilimdali.ad %\> : \<input type="checkbox" name="\<%=  
@anabilimdali.ad %\>" value="0"/\>\<br /\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\>  
&nbsp;&nbsp;&nbsp;&nbsp;\</p\>

\<p\>\<label for="yayin\_ogretimuye"\>Yazarlar\</label\>\<br /\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%for ogretimuye in @ogretimuye%\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<select name=ogretimuye[[ogretimuye.id](http://ogretimuye.id)][] multiple\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<option value="\<%=[ogretimuye.id](http://ogretimuye.id)%\>"\> \<%=[ogretimuye.ad](http://ogretimuye.ad)%\>  
\<%=ogretimuye.soyad%\> \</option\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%end%\>  
\</p\>  
&nbsp;&nbsp;&nbsp;&nbsp;\</select\>

&nbsp;&nbsp;&nbsp;\<%= submit\_tag "Create" %\>  
\<%= end\_form\_tag %\>

\<%= link\_to 'Back', :action =\> 'list' %\>

And the development.log

Processing YayinController#create (for 127.0.0.1 at 2005-12-17  
12:52:05)  
[POST]  
&nbsp;&nbsp;Parameters: {"commit"=\>"Create",  
"ogretimuye"=\>{"[ogretimuye.id](http://ogretimuye.id)"=\>["161"]}, "yayin"=\>{"ad"=\>"888888888"},

"action"=\>"create", "controller"=\>"yayin", "AAT\375p"=\>"0"}  
&nbsp;&nbsp;e[4;36;1mAnabilimdali Load (0.000000)e[0m e[0;1mSELECT \* FROM  
anabilimdali e[0m  
&nbsp;&nbsp;e[4;35;1mOgretimuye Load (0.079000)e[0m e[0mSELECT \* FROM  
ogretimuye  
e[0m  
&nbsp;&nbsp;e[4;36;1mYayin Columns (0.015000)e[0m e[0;1mSHOW FIELDS FROM  
yayine[0m  
&nbsp;&nbsp;e[4;35;1mSQL (0.000000)e[0m e[0mBEGINe[0m  
&nbsp;&nbsp;e[4;36;1mSQL (0.000000)e[0m e[0;1mINSERT INTO yayin (`kabul_yil`,  
`yayin_yil`, `ad`, `cilt`, `index_tur`, `ozet`, `issn`, `sayfalar`,  
`yayinlayici`, `tur`, `yer`, `yer_tur`, `dil`, `index`, `sayi`,  
`anahtar`, `yerli_yabanci`) VALUES(0, NULL, '888888888', NULL, NULL,  
'',  
NULL, NULL, '', '0', NULL, '0', '', NULL, NULL, '', '')e[0m  
&nbsp;&nbsp;e[4;35;1mSQL (0.047000)e[0m e[0mCOMMITe[0m  
&nbsp;&nbsp;e[4;36;1mAnabilimdali Columns (0.000000)e[0m e[0;1mSHOW FIELDS FROM

anabilimdalie[0m  
&nbsp;&nbsp;e[4;35;1mAnabilimdali Load (0.000000)e[0m e[0mSELECT \* FROM  
anabilimdali LEFT JOIN anabilimdali\_yayin ON [anabilimdali.id](http://anabilimdali.id) =  
anabilimdali\_yayin.anabilimdali\_id WHERE (anabilimdali\_yayin.yayin\_id =

20 ) e[0m  
&nbsp;&nbsp;e[4;36;1mSQL (0.000000)e[0m e[0;1mBEGINe[0m  
&nbsp;&nbsp;e[4;35;1manabilimdali\_yayin Columns (0.015000)e[0m e[0mSHOW FIELDS  
FROM anabilimdali\_yayine[0m  
&nbsp;&nbsp;e[4;36;1mSQL (0.000000)e[0m e[0;1mINSERT INTO anabilimdali\_yayin  
(`anabilimdali_id`, `yayin_id`) VALUES (41, 20)e[0m  
&nbsp;&nbsp;e[4;35;1mSQL (0.047000)e[0m e[0mCOMMITe[0m  
&nbsp;&nbsp;e[4;36;1mOgretimuye Columns (0.016000)e[0m e[0;1mSHOW FIELDS FROM  
ogretimuyee[0m

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [18 December 2005 20:08 UTC](https://rubytalk.org/t/passing-multiple-parameters-with-select-option-to-controller/23379/2 "2005-12-18T20:08:04Z")

</div>

You'll want to ask on the Rails mailing list.

[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

> **···**
>
> On Dec 17, 2005, at 11:42 AM, serbulentunsal@gmail.com wrote:
> 
> > I'm using Windows Xp, Mysql 5, Webrick, Rails 1.0 I've 3 tables which  
> > have HABTM relationship.
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
