Forum: Ruby on Rails Post problem with select lists

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 N. (Guest)
on 2005-12-29 10:19
(Received via mailing list)
hey,

i have this problem

how come i always get -1 for the select list??

rhtml

First, select a client.
<select id="client_id" name="client[id]" onChange="submit();" >
<%= options_for_select(@client_options, @client_id.to_i) %>
</select><%= @client_id %>


controller
if @request.post?
	if @request.xml_http_request? #called by ajax,
		@client_id = -2
	else
		@client_id = -11#params[:client][:id].nil? ? -11 :
params[:client][:id]
	end
else
	@client_id = -1
end

shouldnt it be-11 ???


Output
First, select a client.
<select id="client_id" name="client[id]" onChange="submit();" >
<option value="-3">Select a client</option>
<option value="3">Twodecode</option>
</select>-1
=?ISO-8859-1?Q?Thibaut_Barr=E8re?= (Guest)
on 2005-12-29 12:28
(Received via mailing list)
Hi Nick

I'd use the script\breakpointer to check what's happening here (put a
breakpoint instruction just above the line you want to check, and launch
the
breakpointer: you'll be able to quickly inspect the variables and know
exactly what happens).

Thibaut
Brutyn N. (Guest)
on 2005-12-29 13:05
(Received via mailing list)
hmmm, doesnt seem to work

i cant find the problem, i made a lot a forms with ruby now, and this
one cant i
get to work :s:s

cant seem to get the value of [:client][:id] , it is always -1
Brutyn N. (Guest)
on 2005-12-29 13:11
(Received via mailing list)
when i do inspect

<%= params.inspect  %>
 {"action"=>"access_geotags", "id"=>"32", "controller"=>"users"}


and in the rhtml
<tr>
	<td colspan="3"><%= check_box "user", "view_all_geotags" %> User may
view all
geotags from the selected clients.</td>
</tr>
<tr>
	<td colspan="3">Or, select the geotags the user can view.</td>
</tr>
<tr>
	<td colspan="3">
	First, select a client.
	<%= @client_id.inspect %>
	<select id="client_id" name="client[id]" onChange="submit();">
		<%= options_for_select(@client_options, @client_id.to_i) %>
	</select>
	</td>
</tr>

output of rhtml

<tr>
	<td colspan="3"><input id="user_view_all_geotags"
name="user[view_all_geotags]"
value="1" type="checkbox"><input name="user[view_all_geotags]" value="0"
type="hidden"> User may view all geotags from the selected clients.</td>
</tr>
<tr>
	<td colspan="3">Or, select the geotags the user can view.</td>
</tr>
<tr>
	<td colspan="3">
	First, select a client.
	3
	<select id="client_id" name="client[id]" onchange="submit();">
        <option value="-1">Select a client</option>
        <option value="235">Belcompany</option>
        <option value="160">BYS</option>
        <option value="3" selected="selected">Twodecode</option>
        </select>
        </td>
</tr>


in the controller

if @request.post?
	@client_id = params[:client][:id].blank? ? -1 : params[:client][:id]
else
	@client_id = 3
end

if @request.post?
	@user_id = params[:id]
	@geotagidlist = params[:selected_geotagtype].blank? ? -1 :
params[:selected_geotagtype]
	@user.update_attribute(:view_all_geotags,
params[:user][:view_all_geotags] )

end

the update works but i cant get the clientid :s:s:s
This topic is locked and can not be replied to.