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])
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 ...
since this problem is closely linked to your user's entries, you gotta
solve it in your view or controller. to not repeat yourself too much
you could add a helper-method for that piece of code you are using to
set your records straight.
since this problem is closely linked to your user's entries, you gotta
solve it in your view or controller. to not repeat yourself too much
you could add a helper-method for that piece of code you are using to
set your records straight.
yes and no, this problem is the same for lots of users that doesn't
follow the US format number and dates ...
I'm using the helpers for displaying the records, but I can't use them
in the controller, so I created two methods in the Application
Controller, at least it's working but not the way Rails is proposing ...
well, helpers are really meant for helping with displaying your data.
thats right. i actually didn't mean to write a helper-method, but a
method (in your controller) to help you with setting your records. my
fault (got lost in translating my thoughts).
i think your aproach of putting it into application-controller is a
good one (as long as you really need that method in more than one
controller).
well, helpers are really meant for helping with displaying your data.
thats right. i actually didn't mean to write a helper-method, but a
method (in your controller) to help you with setting your records. my
fault (got lost in translating my thoughts).
i think your aproach of putting it into application-controller is a
good one (as long as you really need that method in more than one
controller).
yes, you're right: helpers are for help no matter where they help ...
well, you could always create a helper with an arbitrary name and
include them in your controller. that way helpers are all huddled
together in one folder, but that special controller_helper gets only
included in controller that depend on it.