# Spent over 24 hours trying to figure this - multiple params

**URL:** <https://www.ruby-forum.com/t/spent-over-24-hours-trying-to-figure-this-multiple-params/92747>\
**Category:** Rails\
**Created:** [April 23, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/spent-over-24-hours-trying-to-figure-this-multiple-params/92747 "2007-04-23T19:32:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [April 23, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/spent-over-24-hours-trying-to-figure-this-multiple-params/92747/1 "2007-04-23T19:32:35Z")

</div>

I feel really stupid spending over 24 hours trying to figure out 1 line  
of code but I still can’t get it.

I have a table addpackages, that I want to update multiple fields from  
table rosters based on the selection of a drop down.

In addpackage.rb:  
def create  
@addpackage = Addpackage.new(@params[“add”])

In new.rhtml (view):  
  
\<%=options\_from\_collection\_for\_select(@rosters, “email”, “lname”,  
selected\_value = nil)%\>

This code works perfect for obtaining the correct email address based on  
drop down and updating the addpackages table. I could replace “email”  
with “fname”, “lname”, etc etc and it would work fine also. Whats  
killing me is I can only get one parameter to pass and update. I  
cannot for the life of me figure out how to pass email, fname, and lname  
based on the selected drop down.

Help!!!

---

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [April 23, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/spent-over-24-hours-trying-to-figure-this-multiple-params/92747/2 "2007-04-23T19:36:58Z")

</div>

Tony M. wrote:

> I feel really stupid spending over 24 hours trying to figure out 1 line  
> of code but I still can’t get it.
> 
> I have a table addpackages, that I want to update multiple fields from  
> table rosters based on the selection of a drop down.
> 
> In addpackage.rb:  
> def create  
> @addpackage = Addpackage.new(@params[“add”])
> 
> In new.rhtml (view):  
>   
> \<%=options\_from\_collection\_for\_select(@rosters, “email”, “lname”,  
> selected\_value = nil)%\>
> 
> This code works perfect for obtaining the correct email address based on  
> drop down and updating the addpackages table. I could replace “email”  
> with “fname”, “lname”, etc etc and it would work fine also. Whats  
> killing me is I can only get one parameter to pass and update. I  
> cannot for the life of me figure out how to pass email, fname, and lname  
> based on the selected drop down.
> 
> Help!!!

You would need to use param\_name[] if you want to be able to read an  
array of parameters instead of just the one value.

For example,

\<% choices = options\_from\_collection\_for\_select(@rosters, :id, :email,  
nil) -%\>  
\<%= select\_tag(“email\_ids[]”, choices, {:multiple =\> true, :size =\> 10})  
-%\>

---

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [April 23, 2007, 7:37pm UTC](https://www.ruby-forum.com/t/spent-over-24-hours-trying-to-figure-this-multiple-params/92747/3 "2007-04-23T19:37:33Z")

</div>

> with “fname”, “lname”, etc etc and it would work fine also. Whats  
> killing me is I can only get one parameter to pass and update. I  
> cannot for the life of me figure out how to pass email, fname, and lname  
> based on the selected drop down.

Don’t. Pass the primary key (ie. ‘id’) in the and then your  
controller look up that roster entry and now you have access to  
everything  
you want.

-philip

---

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [April 23, 2007, 7:50pm UTC](https://www.ruby-forum.com/t/spent-over-24-hours-trying-to-figure-this-multiple-params/92747/4 "2007-04-23T19:50:37Z")

</div>

Philip H. wrote:

> > with “fname”, “lname”, etc etc and it would work fine also. Whats  
> > killing me is I can only get one parameter to pass and update. I  
> > cannot for the life of me figure out how to pass email, fname, and lname  
> > based on the selected drop down.
> 
> Don’t. Pass the primary key (ie. ‘id’) in the and then your  
> controller look up that roster entry and now you have access to  
> everything  
> you want.
> 
> -philip

Okay I made the folling changes to view:  
  
\<%=options\_from\_collection\_for\_select(@rosters, “id”, “lname”,  
selected\_value = nil)%\>

Now in my controller can you give an example of how to set:  
roster.fname = addpackage.fname (I know my syntax is incorrect)

Thanks very much for your help, much appreciated. This is my first time  
with RoR.

---

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [April 24, 2007, 4:03am UTC](https://www.ruby-forum.com/t/spent-over-24-hours-trying-to-figure-this-multiple-params/92747/5 "2007-04-24T04:03:30Z")

</div>

Philip H. wrote:

> > > 
> > 
> > roster.fname = addpackage.fname (I know my syntax is incorrect)  
> > Dn’t you mean the other way? I think you do… so…
> 
> p = Package.new  
> r = Roster.find\_by\_id(params[:add][:id])  
> p.fname = r.fname
> 
> …

Thank you! Your help was very much appreciated. And yes you were  
correct I typed it backwards.

---

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [April 23, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/spent-over-24-hours-trying-to-figure-this-multiple-params/92747/6 "2007-04-23T20:04:37Z")

</div>

> > 
> 
> roster.fname = addpackage.fname (I know my syntax is incorrect)  
> Dn’t you mean the other way? I think you do… so…

p = Package.new  
r = Roster.find\_by\_id(params[:add][:id])  
p.fname = r.fname

…
