AR converts params to integer


It seems like AR is auto-converting the string from form into an
integer (for an attribute of an integer column). However, for custom
validation I don’t want it to do this - I want to have access to the
actual string.

I create the model like this:

@model =[:model])

Yet, in Model, column_name shows 5
(params[:model][:column_name] = 5.6).

Any clues on how to change this?

Thanks a lot,


On 1 November 2006 14:58, [email protected] wrote:

(params[:model][:column_name] = 5.6).

Any clues on how to change this?
You should use column_name_before_type_cast reader to get raw data that
has supplied. It is described in AR docs:

= Accessing attributes before they have been typecasted

This is especially useful in validation situations where the user might
a string for an integer field and you want to display the original
back in an error message. Accessing the attribute normally would
typecast the
string to 0, which isn’t what you want.

Thanks a lot Maxim, that’s exactly what I’d missed.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs