Form field returns string instead of int

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

produces:

Please
select

Hygenist Assistant Doctor Practice

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?

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.

On Jan 4, 2008 1:02 PM, spokra [email protected] wrote:

Hygenist


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

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…

Indeed

On Jan 4, 2008 1:18 PM, spokra [email protected] wrote:

=>true}) %>
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?


Ryan B.http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.- Hide quoted text

  • Show quoted text -


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

turns out :type must be used internal to AR… I changed
to :accounttype and updated the table and everything worked… AR knew
it was an INT and saved it correctly!!

maybe a standard of prepending internal symbols with the classname
would eliminate collitions

You want to do:

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

or something similiar.

On Jan 3, 2008, at 8:32 PM, spokra wrote:

Hygenist Assistant Doctor Practice

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?

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.