Hello,

I need to change/adapt of the date and float numbers the user enters:

dd/mm/yyyy I have to change into yyyy-mm-dd

and numbers, replace the , with the .

1245,85 => 1245.85

I thought the best place was using the before_validation() but here the
objects come with standard Rails formats, and the date is wrong, and the
numbers are also wrong.

Now I'm doing all the stuff in the Controller:

 def update

   @transaction=Transaction.find(params[:id])

if @transaction.update_attributes(params[:transaction])

   @transaction.data=convert_european_date(@transaction.data.to_s)
   @transaction.amount = params[:transaction][:amount].to_s.gsub(',',
'.').to_f

end

...


But this is a pain If I have to duplicate code for new and update
controllers method.

So I tried to move the code into the model before_validation but there
the self.data and self.amount are wrong, as Rails adapt them to what
they think it's the standard way ...

In the controller I can get the fresh value from params, but in the
model it doesn't exist ...

what's the best solution to my problem ?

thanks!

r.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to