-
A user enters $100 into a textfield and submits, I need to strip off
the $ sign before it gets saved to the db. -
The name of the field is “price”, why does params[:price] upon
submitting have nil value?
Petr wrote:
A user enters $100 into a textfield and submits, I need to strip off
the $ sign before it gets saved to the db.The name of the field is “price”, why does params[:price] upon
submitting have nil value?
-
“$100.00”.scan(/[.0-9]/).to_s will return 100.00. If you don’t want
decimal values then remove the period, but know that it will return
10000 -
You need the model in front of it. e.g.
params[:your_model_name][:price]
Hope this helps. Perhaps there is a better way to achieve number one,
but that was the quickest thing I thought of.
Regards,
Michael
value = params[:price].gsub(/$$/, ‘’) # strip off a dollar sign if
it’s
the first character
- Not sure. What does you log say? is the param :price => $100 or is it
:model_name => {:price => $100}
–
View this message in context:
http://www.nabble.com/Convert-currency-into-number-tf2043757.html#a5626980
Sent from the RubyOnRails Users forum at Nabble.com.