Forum: Ruby on Rails return value from collection_select

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kathy S. (Guest)
on 2007-01-18 17:09
OK, i have a simple collection_select problem and I'm a newbie to
ruby... I have a form that the user will select a bunch of stuff on to
search through a database.

I can't figure out how to get the return value out of a
collection_select.  Here is the code that displays a drop-down list of
all ip addresses from a table - this works fine.  I make my selection
(along with others on the form) and want the result from this
collection_select assigned to the value ipaddr.

@ipAddress.find_all
collection_select ("IpAddress", "ip", @ipaddress, :id, "ip")  ** this
works fine, everthing displays

In my controller, I do:
    @ipaddr = params[:ip]

This is obviously wrong as I get an error saying "Select * from
ip_addresses where (ip_addresses.ip is NULL) ????

If I use a text input box with the following code, everything works
fine, so I'm pretty sure the controller code is ok - just don't know how
to get the result code from collection_select.

    <input type="text" name="ipaddr">   ** this works, but I don't want
the user to have to type the IP address in - I want them all displayed
to choose from.  Thanks.
This topic is locked and can not be replied to.