Gumby
(Gumby)
1
<%= select( "user" , "type", { "Practice" => 1, "Doctor" => 2,
"Hygenist" =>3, "Assistant" => 4 }, {:include_blank => false, :prompt
=>true}) %>
produces:
<select id="user_type" name="user[type]"><option value="">Please
select</option>
<option value="3">Hygenist</option>
<option value="4">Assistant</option>
<option value="2">Doctor</option>
<option value="1">Practice</option></select> </p>
and the form returns a string. how do i get the form to submit an
int.. or get AR to convert it? select fields can return an int right?
radar
(Ryan Bigg)
2
params[:user][:type].to_i
All int’s submitted by fields are actually submitted as strings. Same goes for dates and anything else, it’s always a string.
Gumby
(Gumby)
3
this would be in the controller in create and update then?
Gumby
(Gumby)
5
forgive me I'm a newbie...
I've tried both
params[:user][:type].to_i
params[:user][:type]=params[:user][:type].to_i
neither work..
John18
(John)
6
You want to do:
@user.type = params[:user][:type].to_i
@user.save!
or something similiar.
Gumby
(Gumby)
7
turns out :type must be used internal to AR.. I changed
it was an INT and saved it correctly!!
maybe a standard of prepending internal symbols with the classname
would eliminate collitions
AR will know what to do with the string. The problem is that you're using the word 'type.' Change it to something else and it will work.
radar
(Ryan Bigg)
9
Damn it, I should’ve noticed.
Yes type is a reserved field in ActiveRecord. It is used for putting types on Single Table Inheritance tables.