Archive for December, 2005

select with value - rubyonrails

Grrr, just spent a little while playing with the “select” form tag in rails. Pain in the ass. The issue I was having is that I want to give users an option of 2 values with a default selected value on the “new” form. I also have a edit form that I want to let users update their objects with, and again, only 2 values. These values are static, and I didn’t want to have the pain of creating a db table, and an object to represent it. That would result in unnecessary code, and unnecessary database hits.

The issue with the “select” tag is that I cannot determine how to set the selected value, without using a collection of objects. I had a look for a solution for this problem, and found this site. This gave me a helper that lets me put in an object, with some methods to get the value and text options for my option set. that was alright. But, I didn’t want the full object model to be supported. I was after a very simple implementation with using a hash, and a string as the selected value.

I hacked around with the code, and this is what I came up with. Please feel free to pillage this.

[sourcecode language='ruby']
def hash_select_with_current(object, method, hash, current_value)
result = “


return result
end
[/source]

Hope that’s useful for someone.

No comment »

Drinking and Hospital

Last night I picked Sarah up from her Mums place, and we went round to Jenna’s place. We started on some wine, and ended up playing some drinking games. We decided to jump the fence at the botannical gardens in christchurch, and go drinking in there. We did that, I snapped some good nighttime pics - available as always on my flickr site. I had a good time. Sarah then decided that she wanted to leave, and I walked her back to Jennas to get her stuff and a taxi for her. Long story short, she spiked her leg on the fence and we ended up in A&E at Christchurch Hospital. We stayed there for about 90 minutes, then Sarah went up and asked how long the wait was going to be. There was a sign we had missed, and it said there was a 6 hour average wait. Seriously, there were like 10 people waiting - and 6 hours! I found that absolutely shocking. Anyway, we packed that in, and went to the 24 hour clinic - Sarah had to pay, but didn’t wait 6 hours. She got 5 stitches.

Crazy night.

Got some good photos tho, particularly the one of June and Leif in the dark - June with her phone, and Leif with a cigarette.

No comment »

BBQ at Andy and Jeanettes

Went out to Andy and Jeanettes (Mr and Mrs Barrett) tonight for a BBQ and some beers. They got a new BBQ a wee while ago with some department store vouchers they got from their wedding. Nice BBQ actually - 4 burner masport thing.

So, we christened it - it hadn’t been used before. It was also Andrews first time (I think) as chief BBQ’er - he did a good job for his 1st time. He discovered that if you have crumbed food on his BBQ, you need oil :-)

After dinner, we played Monopoly. Andrew is a big star wars fan, and Jeanette got him Star Wars monopoly for Xmas. So we played that. It appears the rules for monopoly have changed from the edition I used to play on. My father has a monopoly set from the 1950’s - it’s quite cool. The standard rules that are different now are whenever you don’t buy a property you land on, it goes to auction. Highest bidder gets it. Also, taxes from the board and fines from community chest don’t go into the middle of the board - they just go back to the bank. On my fathers version, if you get fined the money goes into the middle of the board and when you land of free parking, you get the $$$.

Because it’s the star wars edition, they have some new rules. The most notable new rule is what happens when you throw a double. Usually when you throw a double, you get to throw again. With this game, you can either throw again, or “use the force”. Each double enables you to do something different. eg, double 1 = move anywhere on the board. Double 3 is get a sith card (old community chest). The best one is double 6. If you throw a double 6, you can challenge anyone for a property they own that they don’t own the complete set of. You each take a die, and highest roll wins. If the challenger wins, the get to take that property. If the defender wins, they don’t lose the property - it’s quite good. Of course, with my bad luck I was 0 for 2 on that.

Jeanette got bored near 10pm, and decided that she’d sell me all of her property for $200. She donated all of her cash to Andrew. I was clearly losing the game, but with her cards I had the majority of the property - and my average property value would have been higher than Andrews. We played till 10pm, added up, and declared it a draw. My net worth would have been slightly ahead, but that’s only because I got a whole stack of property for real cheap. I had quite a fun time.

I stayed late into the night, and ended up staying here.

Got to go back to my parents soon - I should be seeing my friend Sarah T from Wellington tonight. She’s in Christchurch until the 28th. I think Jenna, Hayley, Sarah and I will be having another boozy evening at Jennas. Last time we did this was about 1 year ago, and Sarah and I got Hayley quite trashed playing Gravy Train - hehehe.

Holidays = a chance for me to give my liver some exercise.

No comment »

Fire Service

I went out to the Christchurch International Airport today, and got to see the fire engines… There are about 5 big engines down there. Got to go for a ride on one of the runways in the fancy new engine - $1.2m purchase price, around $300k commissioning cost. It carries around 10k litres of water. The main water cannon can shoot water up to 70 metres. VERY impressive. I got to control the cannons - that was quite cool. They were surprisingly responsive. There are a couple of joysticks - one for the nose mounted cannon, and one for the top mounted one. Very good.

The new truck has around 680hp, and weighs 33 tonnes. It has quite good acceleration given its weight.

Big thanks to Richard and his father for letting me go out there.

Pictures on flickr.

No comment »

Xmas Day

I arrived at my parents place at around 8am. My sister was the only one up. I quickly downed some panadol, and went and had a shower. I could feel the headache coming on.

Basically, we after this, we had breakfast, opened some Xmas presents, went to my Grandpa’s place to pick him up to bring him back out to the farm. After we got back out here, I went for a bit of a nap. Zzzzzz. Slept till lunchtime. Ate waaaaaaayyyyy too much food. After this, we drank Cognac and Brandy, and then I went for another nap. Got up again at 7pm, watched some figure skating on TV, and now back to bed.

The most fun thing of the day was seeing Richard’s dog Luke open his Xmas present. He was given it (wrapped up), took it outside, and unwrapped it. It was a rubber, squeaky hamburger (dog toy). He then proceeded to destroy it over the next hour or so. I’ve put some pics of the unwrapping by him on flickr.

A very lazy day indeed. Successful, but lazy.

Tomorrow I’m intending to go to the airport with my sister and her boyfriend to see his father. His father is a fireman out there, and we should be able to go for a ride in the brand new $1.5 million dollar fire engine. I enjoy that sort of technology and engineering - should be fun. I’ll take pics and post them.

Oh, I added a new site to my design/lifestyle set on del.icio.us. It’s TROIKA - a german design house. I quite like their products, and got a keyring of theirs for Xmas. Snazzy.

No comment »

Xmas Eve

Went to Jennas place today. Her friend Amy who was up in Christchurch from Timaru came over. We headed to the Dux and caught up with another friend of theirs, Becky. The dux was so busy - completely packed out. Only stayed there for one beer, then we went back to Jennas place for more drinks. Eventually a whole stack of people came over, we polished off bottles of Whiskey, Vodka, and Gin. Met a bunch of new, fun people which was great. I’ll post the pics to flickr.

Got to bed at about 3:30am - 4am - not quite sure really. I got up at around 7:30am to get my ass back to my parents place for Xmas. The roads were dead that early on Xmas day.

Had a great night, but paid for it on Xmas day.

No comment »

Go PayPal!

Woohoo! I got PayPal IPN integration working. Now you can register with my application, make a payment via PayPal, and PayPal will come back to my web app and let me know that you’ve registered. Clever stuff.

I used the PayPal IPN GEM from http://dist.leetsoft.com, and integrated it with my own Payment object. I don’t really have the need for a full “ordering”-type system with my application. There is only ever 1 line item per order, so only a single payment object is required. I could have implemented an order, with order_line_items, and shipping and billing addresses, and tax and handling calculations, but I don’t need them.

I need to look into the IPN integration a little more tho. When I say I’ve got it working, I mean I’ve had 1 payment through that successfully updated a users registration details. PayPal seem to be pushing the transaction to me twice - I handle that correctly (checking for unique transaction IDs), but I think I need to respond to them in some other way. I better re-read those docs.

I’m quite pleased. Maybe a congratulatory coffee & and an apple are in order.

No comment »

Money, Ruby on Rails and AUD

I had a bit of a play with the Money and Paypal GEMs available at http://dist.leetsoft.com . The Money API only supports Euro, US and Canadian dollars. For my paypal integration, I need to support Australian dollar (as dirty old paypal don’t support NZD). So, I’ve extended the Money class to create an AUD implementation. There’s nothing special about it, but if you’re too lazy to write the couple of lines of code yourself, here it is.

Also, I’ve been having a bit of trouble getting the Money and Paypal GEMs to work. The issue is that from within a rails controller it doesn’t recognise the Money or Paypal classes. It can’t find them. This is the only GEM that I’m having troubles with. My solution was to import the .rb files into the /vendor directory. If anyone has this problem, or has a solution for this problem - or even tips, please let me know. It’s annoying me now.

If I can get this working, I won’t bother with my own IPN implementation. Why reinvent the wheel?

No comment »

Hey. Been out at pub quiz this evening. Tomas an…

Hey. Been out at pub quiz this evening. Tomas and me. We got last. We suck so much. Lost by 5 points. Couldn’t answer any of the first 7 questions - bloody current affairs, and local sports. Why do I pay so little attention to local sports. It’s really because I just don’t care about how local team x is going against foreign team y. Proletariats and their distractions I guess. And then we stayed for the open mic night. First lady was depressing, 2nd dude was alright. 3rd dude was this freaky modern beatnik poet - so random. 4th was this dude who was quite good. last we saw was this lady who’s stage demeanor was equivalent to that of Jewel. She was a really good singer too. I[’d buy her CD if she released one.

Tomas and Jon went off to the Drake. I went home. I’ve got a conference call with VFUK in the morning (urrrg, 7-am) about a job. Fingers crossed.

I’m a bit boozed.

No comment »

Every day’s a Saturday

Had lunch with my friend Brodie today… We went to De Fontein at Mission Bay. Had a good talk about what’s going on with me. It was nice to see her. I think when I leave NZ I’ll go to Sydney for a couple of days and catch up with Matt, Brodie(the Matt in that pic ain’t the Matt I reference before) and J. Will be nice to see all of them before I leave this part of the world.

Good progress on the job front last week. Promising feedback from a couple of people. Fingers crossed.

And, tonight was “Christmas in the Park” here in Auckland. I didn’t go, but I still got to see the fireworks. From my place I could see them - they were quite impressive. Couldn’t see all of the fireworks tho, only the ones that mattered :-) (the big, impressive fireworks).

No comment »