![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
Haven't really created any "proper" tests since I actually only have one controller at the moment and I can test it via browser |
|
All of my methods work however whenever I do an update it doesn't touch the set method to change the variable. (Tested with simple outputing text to say that it was being used) |
|
On Nov 7, 8:59�pm, Marnen Laibow-Koser <rails-mailing-l...@andreas- |
#12
| |||
| |||
|
|
7H3LaughingMan wrote: Haven't really created any "proper" tests since I actually only have one controller at the moment and I can test it via browser Not an excuse. *You should write tests before writing any application code at all. *That way you know your code does what you meant it to. Read up on test-first development and apply the practice religiously. All of my methods work however whenever I do an update it doesn't touch the set method to change the variable. (Tested with simple outputing text to say that it was being used) Right. *I don't think update_attribute would. On Nov 7, 8:59 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/. --~--~---------~--~----~------------~-------~--~----~ |
#13
| |||
| |||
|
|
Alright I wrote a test and figured out what was wrong turned out that I had the form submitting the data to the edit section of the controller instead of the update section. |
|
I fixed it and it all works out, when you use update_attributes it does use the override of the set method. |
|
Now then my only question now is where can I put the universal methods that are going to be used by Models and Views, and Controllers / Helpers if they need to be used by them. I read somewhere where you would put it but since then I have forgotten and can't find it again. |
#14
| |||
| |||
|
|
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. ![]() |
#15
| |||
| |||
|
|
Now then my only question now is where can I put the universal methods that are going to be used by Models and Views, and Controllers / Helpers if they need to be used by them. I read somewhere where you would put it but since then I have forgotten and can't find it again. |
#16
| |||
| |||
|
|
Now then my only question now is where can I put the universal methods that are going to be used by Models and Views, and Controllers / Helpers if they need to be used by them. I read somewhere where you would put it but since then I have forgotten and can't find it again. |
#17
| |||
| |||
|
|
Marnen Laibow-Koser wrote: 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. ![]() As promised, I've refactored and improved (I hope!) your code. *The new version is athttp://pastebin.com/f4b92e46d. One suggestion I didn't get to make in the source (because the method no longer exists with that name): convertDNDtoInt is not a Ruby-style name. The more Rubyish name would be convert_dnd_to_int. Best, -- Marnen Laibow-Koserhttp://www.marnen.org mar... (AT) marnen (DOT) org -- Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ |
#18
| |||
| |||
|
|
Thanks for the help, I was already in the process of converting it into it's own separate class and having it always loading automatically. But right now I am having some issues mostly with carrying numbers across (mostly downwards). The idea is to have methods where I can get and set the individual values (pp, gp, sp, cp). However if the value is set to a number below 0 it would... 1. Go up a level subtract one. 2. Add 10 to itself 3. Continue I would like for it to always go downwards and thought I could use some recursion to keep these methods DRY. I don't want conversions being done unless it needs to be done. A person can't take 10 cp and magically turn it into 1 sp but if he purchases something that is 1 sp they can use 10 cp since it's the same value. But with the current way I was planning it would of had issues with infinite recursion and yadda yadda yadda. But here are some examples... 1. 10 gp - 1 sp = 9 gp 9 sp 2. 200 cp - 2 gp = 0 cp 3. 10 sp - 1 pp = 0 cp (Not letting it get below 0, since normally this wouldn't happen unless under certain cirmstances) http://pastebin.com/d420d085a |
|
I was going to add some options to where if it was set to something below 0 that it would automatically subtract 1 from the one above it, add 10 to itself, and continue doing the math while repeating if necessary with recursion. However that would be in issue if the one above it was 0 since if it was subtracted by 1 it would set the one below it to -1 causing it to repeat indefinitely. I hope this kind of makes since, and I am kind of stumped on doing this without an insane amount of repeated coding. |
|
FYI: I will probably add another class the is an extension called BankMoney, since the Bank has no issue converting automatically upwards or downwards and they also allow for negative ammounts. On Nov 8, 11:00�pm, Marnen Laibow-Koser <rails-mailing-l...@andreas- |
#19
| |||
| |||
|
|
7H3LaughingMan wrote: Thanks for the help, I was already in the process of converting it into it's own separate class and having it always loading automatically. But right now I am having some issues mostly with carrying numbers across (mostly downwards). The idea is to have methods where I can get and set the individual values (pp, gp, sp, cp). However if the value is set to a number below 0 it would... 1. Go up a level subtract one. 2. Add 10 to itself 3. Continue I would like for it to always go downwards and thought I could use some recursion to keep these methods DRY. I don't want conversions being done unless it needs to be done. A person can't take 10 cp and magically turn it into 1 sp but if he purchases something that is 1 sp they can use 10 cp since it's the same value. But with the current way I was planning it would of had issues with infinite recursion and yadda yadda yadda. But here are some examples... 1. 10 gp - 1 sp = 9 gp 9 sp 2. 200 cp - 2 gp = 0 cp 3. 10 sp - 1 pp = 0 cp (Not letting it get below 0, since normally this wouldn't happen unless under certain cirmstances) http://pastebin.com/d420d085a The easiest way to do this, I think, would be to define class Currency, with subclasses (or perhaps instances) SilverPiece, GoldPiece, and so on. *There's lots of info floating around on handling multiple real-world currencies; you should be able to do D&D money the same way. I was going to add some options to where if it was set to something below 0 that it would automatically subtract 1 from the one above it, add 10 to itself, and continue doing the math while repeating if necessary with recursion. However that would be in issue if the one above it was 0 since if it was subtracted by 1 it would set the one below it to -1 causing it to repeat indefinitely. I hope this kind of makes since, and I am kind of stumped on doing this without an insane amount of repeated coding. Use the power of a decent object model. *I'll try to post a quick example if I have time. FYI: I will probably add another class the is an extension called BankMoney, since the Bank has no issue converting automatically upwards or downwards and they also allow for negative ammounts. On Nov 8, 11:00 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/. --~--~---------~--~----~------------~-------~--~----~ |
#20
| |||
| |||
|
|
http://pastie.org/691288 I did some fine tuning and came up with a rather interesting way of keeping all of it to one class to represent the money. This is an example of one of the sets, the others look like this with a few changes. At the moment if it tries to be set to something below 0 it will take it from itself and if necessary work it's way up first and then down. I haven't been able to test this yet but I would love it if you could take a look at it and see if there might be a way to cut it down some more (The original was hideous!) |
|
Hopefully if I keep it to this one class then I could finally take a step forward and continue adding more and more to the database. |
![]() |
| Thread Tools | |
| Display Modes | |
| |