On Nov 12, 10:47 pm, Karine Delvare
<kdelv...-T/o0Z7lmwKpeoWH0uzbU5w@public.gmane.org>
wrote:> Hello,
>
> I used a migration to add an integer column to one of my data tables:
> add_column :lien, :cpc, :integer, :null => false
>
> The user is not interested in this integer, but in 1/1 000 000 of it.
> So, in my form partial I used a text_field as usual:
> <%= text_field ''lien'', ''cpc'' %>
> But in my controller, I modify the cpc value to get an integer:
> def edit_lien
> @lien = Lien.find(params[:id])
> @lien.cpc /= 1000000
> end
> def update_lien
> @lien = Lien.find(params[:id])
> @lien.update_attributes(params[:lien])
> @lien.cpc *= 1000000
> @lien.save
> end
>
> This works great as long as the user enters an integer value in the
> text field (if ''3'' is entered, the database contains
3000000 and the
> user still sees ''3'' when re-editing). But decimal values
are truncated
> (if ''1.5'' is entered, the database contains 1000000
instead of 1500000).
>
> I guess that''s because I defined my cpc column as integer in the
first
> place, can I tell Rails to not truncate decimal values as I will use
> them, or should I have gone another way to make this work properly?
>
> Thanks,
> Karine
Then don''t use update_attributes. Set your attributes one by one.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---