![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| ||||
| ||||
|
|
I would like to know if it is possible to alter a variable during the process of a custom validation. I know that it is no longer validation when your altering data but in my opinion there are times when you need alter it for simplicity sakes. |
|
A good example would be for a world wide auction house type application and to to convert currency to one single format, when you validate you check to see if both the amount is alright along with the currency type. (This is assuming you can type in what type of currency it is, and for this example is possible.) |
|
The application I am developing allows the user to type in multiple currencies at one (This is a D20 RPG, and people type in something along the line of 12 pp 145 gp 78 sp 21 cp) and so far the validation process involves converting it all to the lowest currency type. |
p => 1000}|
for the sake of being DRY I would only need to add another line to set the variable, but instead it is looking like I would have to repeat the whole method and add in the single line and change it that way on creation and updates. |
#3
| |||
| |||
|
|
I would like to know if it is possible to alter a variable during the process of a custom validation. I know that it is no longer validation when your altering data but in my opinion there are times when you need alter it for simplicity sakes. A good example would be for a world wide auction house type application and to to convert currency to one single format, when you validate you check to see if both the amount is alright along with the currency type. (This is assuming you can type in what type of currency it is, and for this example is possible.) The application I am developing allows the user to type in multiple currencies at one (This is a D20 RPG, and people type in something along the line of 12 pp 145 gp 78 sp 21 cp) and so far the validation process involves converting it all to the lowest currency type. But for the sake of being DRY I would only need to add another line to set the variable, but instead it is looking like I would have to repeat the whole method and add in the single line and change it that way on creation and updates. --~--~---------~--~----~------------~-------~--~----~ |
#4
| |||
| |||
|
|
I would put this in a callback in the controller. I suggest starting at before_save and go from there. |
|
-eric |
#5
| |||
| |||
|
|
Eric wrote: I would put this in a callback in the controller. I suggest starting at before_save and go from there. That would work, but I think it's conceptually wrong for what the OP wants. -eric Best, -- Marnen Laibow-Koserhttp://www.marnen.org mar... (AT) marnen (DOT) org -- Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
Alright I have set it all up and it will convert it to the lowest form (and back for debugging purposes), however whenever I try to edit and save using @armor.update_attributes(params[:armor]) it fails for some reason. |
|
Here is a link to show you what I did with the model... http://pastebin.com/me807521 |

#8
| |||
| |||
|
|
7H3LaughingMan wrote: Alright I have set it all up and it will convert it to the lowest form (and back for debugging purposes), however whenever I try to edit and save using @armor.update_attributes(params[:armor]) it fails for some reason. Fails in what way? Here is a link to show you what I did with the model... http://pastebin.com/me807521 I'll check it out in detail later on. *On cursory inspection, however, it looks like it has a lot of problems; I'll make some suggestions when I'm not trying to type on my iPhone. ![]() Perhaps Eric's before_save suggestion is the right idea after all. Best, -- Marnen Laibow-Koserhttp://www.marnen.org mar... (AT) marnen (DOT) org -- Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ |
#9
| |||
| |||
|
|
I don't know how it fails but for some reason it refuses to update when I edit it, I have it setup to where it goes back to the index when you successfully edit something and when it doesn't work it goes back to the edit page. It doesn't even throw any error messages. |
|
On Nov 7, 3:30�pm, Marnen Laibow-Koser <rails-mailing-l...@andreas- |
#10
| |||
| |||
|
|
7H3LaughingMan wrote: I don't know how it fails but for some reason it refuses to update when I edit it, I have it setup to where it goes back to the index when you successfully edit something and when it doesn't work it goes back to the edit page. It doesn't even throw any error messages. I'll pay special attention to that, then. *Are your tests passing? On Nov 7, 3:30 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas- Best, -- Marnen Laibow-Koserhttp://www.marnen.org mar... (AT) marnen (DOT) org -- Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ |
![]() |
| Thread Tools | |
| Display Modes | |
| |