Forum: Ruby on Rails problem with options_from_collection_for_select() need id no

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.
brutyn_nick (Guest)
on 2005-12-01 11:39
(Received via mailing list)
hey,

i need a select list with a id property and not name, cuz i just ajax
with this
list and it checks on id not name

if @request.post? #called by ajax
	if @request.xml_http_request? #called by ajax
		@geotag_id=params[:geotag_id].nil? ? -2 : params[:geotag_id]
	else
		@geotag_id=params[:geotag][:id].blank? ? -1:params[:geotag][:id]
	end
else
	@geotag_id = -1
end

i use this

@geotags = Geotag.find(:all, :conditions =>['firm_id = ? and client_id =
? ',
firm_id, client_id])
@geotag_options = @geotags.collect {|g| [g.address1 + ", " + g.address2
+ ", "
+g.floor + ", " + g.city ,g.id]}

<%= select("geotag", "id", @geotag_options) %><br/>

<select name="geotag[id]">
<option value="%">All</option>
<option value="1">Foster Park 2, Brugge (VME Complex Foster)</option>
<option value="8">Foster Park 4, Brugge (VME Complex Foster)</option>
<option value="5">Gistelsteenweg 1, Brugge (Odevaere (VME
res.))</option>
<option value="12">Molenaarsstraat 24, Oostende (Gevens)</option>
<option value="11">Rederskaai 39, Zeebrugge (VME Complex
Foster)</option>
</select>

but no id tag

i can work with this, here i got an id and the submit works

<select id="geotag_id" name="geotag_id">
<%= options_from_collection_for_select(@geotags, "id", "address1") %>
</select>

but i also need address2 and floor, and this seems not to work

<select id="geotag_id" name="geotag_id">
<%= options_from_collection_for_select(@geotags, "id", "address1" +
"address2" +
"floor") %>
</select>

can anyone help me?
This topic is locked and can not be replied to.