spokra
January 4, 2008, 3:33am
#1
<%= 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?
spokra
January 4, 2008, 3:45am
#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.
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.
spokra
January 4, 2008, 3:48am
#3
this would be in the controller in create and update then?
spokra
January 4, 2008, 4:15am
#4
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…
spokra
January 4, 2008, 3:58am
#5
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
–
Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.
spokra
January 4, 2008, 4:44am
#6
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
spokra
January 4, 2008, 4:44am
#7
You want to do:
@user.type = params[:user][:type].to_i
@user.save !
or something similiar.
spokra
January 4, 2008, 4:50am
#8
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.
spokra
January 4, 2008, 5:59am
#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.