form field returns string instead of int

<%= select( "user" , "type", { "Practice" => 1, "Doctor" => 2, "Hygenist" =>3, "Assistant" => 4 }, {:include_blank => false, :prompt =>true}) %>


<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?


All int’s submitted by fields are actually submitted as strings. Same goes for dates and anything else, it’s always a string.

this would be in the controller in create and update then?


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..

You want to do:

@user.type = params[:user][:type].to_i!

or something similiar.

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.

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.