My Octopress Blog

A blogging framework for hackers.

Using Globalize Without Changing Your Resource Links

Using Globalize without changing your resource links

NOTE: This page was created in order to get ideas going, and thankfully it did just that. Please have a look at Sven’s more elegant solution.

One of the projects I’m working on needs to have internationalization, so almost exactly after seeing Jeremy Voorhis talk about Globalize at Canada on Rails, I have finally installed it and taken a look around.

Despite some limitations, such as potentially large database tables if you have a lot of languages and the disabling of :through relationships, it’s a very slick plugin. It’s almost entirely invisible. You install it, add a line to each model that you want translated and you’re pretty much good to go. Sits nicely right on top of your app.

Now, being the eccentric perfectionist I am, I would really like the locale to be in the URL so that:

  • people can bookmark their page and still have the correct language
  • search engines will find and parse multiple languages
  • people can send a link to their friend in the same language

After following a wonderful Globalize tutorial by Sven Fuchs my localized urls were setup in a matter of minutes, with only 1 caveat.

When using named routes and the resourceful helpers you just need to pass the locale in as the first parameter, like this:

article_path(@current_locale,@article)

Easy enough, right? Well.. not to me. Every application I build these days uses restful routes, and having to pass the current locale into each link on every page really removes the invisible nature of the Globalize plugin and seems like unnecessary meta data. I really want the app to know it’s current_locale and behave accordingly, unless I want to change the locale. It should be:

article_path(@article)

Go ahead, call me picky. ;)

So off I go, digging into the Rails 1.2 Source Code looking for the magic that will make this all work well for me. Low and behold, I found it.. and wouldn’t you know it, it was only one line that needed to be added to the define_url_helper method.

#{'args << { :locale => @current_locale }' if segment_keys.include?(:locale)}

This line, when placed at row 78 of routing.rb prepends the current_locale to any route that has :locale defined as a key.

A few copy and pastes and some manual testing later, I have exactly what I want.

I have created a pastie for you to look over. It is very hackish right now, but I was just talking to Jeremy Voorhis. He said we might be able to clean it up and include it as an optional module in Globalize so that you don’t have to include yet ANOTHER plugin in your app.

The Pastie: Adding locale to your URL using Rails and Globalize

Have a look. Give it a shot. Let me know what you think. :)

Dating Tips - Getting Out of Your Own Way

I’m just watching Hitch (for the 5th time) and there was something that I didn’t like about the ending.

Hitch goes through the whole movie teaching guys how to act on a date. What to do, what not to do, how to dress and what situations to put themselves in. He even goes so far as to make Albert get his back waxed. He builds a fairly tidy and successful business out of this, so obviously it’s effective.

Then we get to the end of the movie, where he is talking to Alegra Cole and she starts listing off the things that she found endearing about Albert. The items that she mentions are all things that Hitch would never teach and would definitely consider a no-no. They are the things that made Alegra connect with Albert and that’s what builds a relationship. I believe the quote that bothers me is “Wait, that stuff worked for you?” Hitch then decides that there are no “Basic Principles” of courting and the whole theory seems to be written off. Herein lies the problem.

What Hitch actually did for his clients was the following:

The first thing is that provided them with an opening and created an opportunity for them to have a chance with their love interest. In today’s busy world, it’s often really hard to separate yourself from the masses and get yourself noticed by someone you’re interested in… especially in a big city.

Secondly, and most important, he provided his clients with the feeling that they had an edge. They had a “professional” working to get them the girl. They had an ace in their sleeve and were a step up. This “edge up” allowed them to woo their interest and build a nice relationship.

There was, however, no edge. All they really got was a reason to have the confidence they should have in the first place. The confidence to stand next to the person they like and actually feel like they are allowed to be there. The confidence to engage that person in a conversation and give them the opportunity to get to know each other. The confidence that yes, they actually COULD do this.

Having that confidence in yourself allows the other person to get to know who you are, without your own personal insecurities getting in the way. No matter what you do, the real you is still going to shine through. If not right away, it will at some point in the near future”¦ and no matter what anyone says, it’s not the gloss that people fall in love with.. it’s the little things that make you who you are. And, as I’ve said before, we all have our bad habits and weird idiosyncrasies but along with those come the unique and wonderful things that someone is going to end up loving.

So, with that in mind, here’s to the Hitches in every city. The friends, moments and wing-men that help you get out of your own way and get to know the person you’re interested in.

Debugging Your Ruby on Rails App

Debugging your Ruby on Rails App

I gave a very quick and dirty presentation tonight at the Vancouver Ruby Brigade meeting. Here are my notes from that talk.

There are a bunch of great tools that help you debug your application in Rails. Here is a quick runthrough.

In A View

<%= debug @object %>
    or
    <%= debug 'string' %>
    or
    <%= 'string'.inspect %>

This will output the data directly on to the page. It’s very useful for taking a look at what you’re working with in the view, or to check if the variable contains any data at all. I use it all the time when I’m throwing up the Show views. I just dump out the object using debug and then use the data to build my layout.

In A Controller

logger.debug "The object is #{@object}"

    RAILS_DEFAULT_LOGGER.debug @object

Both of these methods will print the the standard logger. The logger.debug method works within your application. The RAILS_DEFAULT_LOGGER will work inside the Rails framework (if you dare dive into it) or inside any libraries where logger is not defined.

return render :text => "The object is #{@object}"

The render :text call will dump the text to the screen and halt execution of the current action. This will allow you to see what you’re working with right away, without having to pass variables to a view. It’s great for quick debugging.

In A Model

Using the RAILS_DEFAULT_LOGGER and logger.debug is one of your best options, if not the only one. If you’re running Mongrel there are some great debugging tools, but I’m not going to go into them now.

Outside The App Folder

script/console

The console is an interactive ruby environment (irb) that has your entire application loaded up into it. You can try different things with your modules, check for dependencies or do maintenance. There are plenty of resources online for script/console tutorials. Have a look at this one to get started: Robby On Rails talks about script/console

To run console, just open terminal (or whatever prompt you have) and run script/console from the application root.

tail

Unix tail , Ahh, I love tail. tail is a little unix app that will show you the end of a file… and if you use the -f option, it will ‘follow’ the end, which keeps showing you the end of the file even if it changes.

from the application root:

tail -f log/development.log

Using this, you can keep an eye on what your applicaiton is doing the whole time. Generally, when I’m developing, I am constantly tailing my development log. Just makes it easy for me.

script/breakpointer

Breakpointer is really straightforward, but for some reason it seems really complex. All you need to do is run script/breakpointer from your appplication root and then put the word ‘breakpoint’ anywhere in your app. When you’re running your app and it hits the ‘breakpoint’, the breakpointer will pick it up and give you an Ruby console to work with. It works the same was as console, but from the current state of your application.

For more information on breakpointer, have a look at HowtoDebugWithBreakpoint

Note: breakpointer has been deprecated (Rails Changeset 6611). Use Ruby Debug.

script/server

If you’re running using Locomotive or .. umm, whatever the windows version is (InstantRails) sometimes you get startup errors and can’t see what they are because they’re enclosed in the launch application.

All you need to do is open up your terminal and type script/server, which will launch your app in webrick or mongrel. if there are any dependencies, it will spit them out and let you know why it can’t startup.

In Production

Install the ExceptionNotification plugin. It’s wonderful. Really. It will e-mail you if the application throws any error messages.

script/plugin install http://dev.rubyonrails.org/svn/rails/plugins/exception_notification/

Just Talk About It

If you’re really stuck on a problem, the best thing to do is to talk to someone (or something) about it. Apparently, the part of your brain that tries to figure out the problem is different than the part of your brain that tries to describe the problem… so just trying to figure out how to explain the problem often shows you what’s wrong and helps you fix it. Even if you just have a plant, pet or robot on your desk to talk to… it’s ok, they’re listening.

Other than that, good luck… and if you’re in Vancouver on the second tuesday of every month, come to a Brigade Meeting. :)

Illanti Cart

When I finally got frustrated by the so called “easy to implement” shopping cart systems, I sat down for two days and wrote my own. From concept to processing live transactions in less than 48 hours. It includes an admin panel, full payment services support and is quotes as being “the most customizable cart [they’ve] ever used.” I have now sold a few copies of the cart, one of which powered the official store for a US basketball team.

Illanti Job Board

After a playful challenge from a friend, I sat down and wrote job board application in 48 minutes flat. It included RSS feeds, Paypal payment support and an admin panel. It has since been packaged and sold off as a product. For a while, it powered Mashable.com’s marketplace.

My Adventures as a 25 Year Old in Disneyland

Disneyland is awesome!

You know, I didn’t think I’d like it. I was sitting in Anaheim all by myself. I had been working almost non-stop and hadn’t had much time to even look around the hotel, let alone check out Anaheim. However, my client cancelled one of our meetings and convinced me that since I was only two blocks away from Disneyland I had better go now while I had the chance. So off I went, all by myself, to Disneyland.

Granted, I didn’t intend to go alone. I sent messages to all the people I knew in LA (and a few that I didn’t) trying to find someone who would go with me, but it being Halloween weekend, everyone was already going to parties that I apparently wasn’t invited to (granted they were over an hour away). I had no idea how Disneyland could be fun on a Saturday night without anyone to talk to while I stood in line, listening to screaming children. I wasn’t really looking forward to it, to be honest.

My first impressions of Disneyland were pretty much what I expected. Once you walk through the gates and go under the train tracks, you’re in a whole new world. You can’t see any of the buildings around you anymore and you’re completely immersed in the brilliant marketing that is Disney. The lines were just as long as I had expected (a good hour and fifteen minutes for Space Mountain) and even though I really had nothing to do but go on rides, the thought of standing in line just really didn’t appeal for me.

So what did I do? I talked to people. I walked around with my camera taking photos and introducing myself to staff and other people who seemed nice. I asked questions about Disneyland, about the park, the history and the rides. My first attempt at a ride was Buzz Lightyear Astro Blasters, since I was told by someone that it was a heck of a lot of fun. I used their FastPass system to get a return time (an hour and a half later) and before heading to walk around again, I stopped to talk to one of the nice girls at the front of the ride. Sarah, as her nametag read, was kind enough to tell me all about how the FastPass works and how to strategically get the shortest times possible. Tips like hitting space mountain right before the fireworks end, etc.

IMG_9341.JPG

After thanking her for her help, I walked around to Fantasyland and Toontown taking pictures and killing time until I head back to Buzz Lightyear at 7:30pm. Despite being for really young kids, Toontown was actually one of the places I was most interested in. I was a pretty big fan of the animated cartoons when I was a kid, so seeing Goofy’s house, meeting Mickey and just checking out the wonderful architecture of the area was very cool for me. I love how overdone everything is. Watching old Mickey cartoons while waiting in line to meet the famous mouse was also a nice blast back in the past.

With 7:30 rapidly approaching, I headed back towards the Buzz Lightyear ride. After two hours in Disneyland, I had still not gone on a single ride. I had only 4.5 hours until the parked closed, so it was about time I saw what they really had to offer. That’s when it started getting fun. :)

7:28 PM

IMG_9375.JPG

I walked through the FastPass gate for Astro Blasters and ran into Sarah at the second position. (In the FastPass rides, there are usually three positions; Entrance Gate, FastPass taker and the actual ride.) She smiled at me and let me hang onto my FastPass so that I could go again. By the time I was at the ride, she had moved to the third position and slipped me a handful of FastPasses so that I could take the ride as much as I wanted. Awesome! Sarah rocked! The ride itself is pretty fun as well. You get a little gun and have to blast targets as you defeat Zurg. I think the 10 year old kid in front of me kicked my ass though. :p

7:50 PM

Heading through Frontierland now, I walk past Big Thunder Mountain Railroad and stop to talk to the girl at the gate. I ask her how long the line is and if it’s worth the wait. She says it’s not bad, and after realizing that it’s my first time she asks me where my 1st Time pin is (my what?!) and hands me a FastPass for the ride! :D I hop into the FastPass line and work my way down to the ride. On the way there, I hear a family talking about what rides they’ve been on and how they are going to get on more with the limited FastPass times they have. Lucky for them, I happen to have a few FastPasses kicking around, so I offer them enough passes to get them all on Astro Blaster and I’m greeted with a huge thank you from the kids and the parents. They should really be thanking Sarah, but I’m more than happy to pass it on.

Big Thunder was the first ride that I really cracked a true smile on. It really set the mood for the rest of the night. I’ve been on a lot of roller costers, but something about this one really made me smile. I got off the ride and was so happy that I went back to the girl at the gate (can’t remember her name) and gave her a big hug.

8:15 PM

I head back to check Space Mountain during the Parade, still over an hour wait. Nope, not worth it. I turn around and decide to stop by Astro Blasters again to thank Sarah and see if I can beat the darn 10 year old. Nope, he still schooled me. ;) Only 3 hours and 45 minutes left.

8:45 PM

This is where it really picked up. I was standing in front of the Pirates of the Caribbean and I asked really nice looking girl named Katie what all the people lining up was for. She explained to me that it was for the 9pm show of Fantasmic!. I then asked her where the best place to watch it from was, and we got into a talk about Disneyland. She turns on the gears, tells me to wait and runs off. Apparently, she also worked in Fantasyland and was going to try and get me onto her favorite ride Small World without me waiting in line. After being unable to get anyone on the phone, she gave me a ‘Citizen of Disneyland’ pin and I went on the Pirates of the Caribbean ride before the fireworks at 9:30pm.

Pirates was pretty good, but nothing compared to some of the other rides. A tremendous amount of detail though. The ride was originally done way before the movie came out, but it has been updated recently to slide Johnny Depp into it. Other than that, it’s a fairly docile water ride. Surprising for a ride that has had multiple hour lineups.

9:30 PM

IMG_9400.JPG

The Pirates of the Caribbean took longer to get through than I expected, so I had to book it to the fireworks as quickly as possible. I ended up getting a really nice spot directly in front of the Castle, but with only about 10 minutes of the show left, so I think I missed most of it. Once that was done, I stop to do a little swing dancing with a fairly cute girl from Orange County before heading back to the Fantasmic show in order to get good seats.

9:50 PM

I bump into Katie again and she tells me exactly where to go in order to get the best spot for the show. I end up right in front of the show, dead center. Perfect view. Of course, I’m there 40 minutes early, so I spent the next 40 minutes sitting on the ground striking up random conversations with strangers. Including a conversation with a very good looking girl about how she never realized how dark and evil Disney was until she came to Disneyland. Funny, that was always what I liked about Disney. :p

10:30 PM

Let me tell you.. Fantasmic! is amazing. I was expecting it to be interesting, but it was unbelievable. They combine live action with video projected onto a wall of water, and the end result is something that’s very hard to describe in words. It’s an absolutely wonderful musical and visual show about the good and bad parts of your imagination and how you can control it. I’m not sure I’d let little kids watch it. It’s really quite dark and scary.

Tom Sawyer’s cabin turns into a dragon, Hook’s pirate ship sails through the lagoon, Steamboat Willie goes for a cruise… everything. Check the wikipedia entry! for more details. It’s just killer.

11:00 PM

I meet up with Katie again after the show, and she decides it’s time I saw Fantasyland. Let me tell you, that girl really knew how to make someone feel special at Disneyland. Had it not been for her, I think this story might have ended after Fantasmic… but she was just wicked. The next 60 minutes is a blur, but I’ll give you the coles notes version. She managed to backdoor me into all the rides in Fantasyland. In a 30 minute period, I went on 4 rides in Fantasyland; Storybook Land Canal Boats, Peter Pan’s Flight, Pinocchio’s Daring Journey, and Mr. Toad’s Wild Ride . Katie introduced me to Pat, who was the REALLY nice woman in charge of Fantasyland and Pat let the people at the gates know that I was coming. It was rocking. I was a Disneyland VIP. Katie even managed to find me a 1st Visit Pin (At last! haha).

11:45 PM

Last but not least, Katie handed me a ‘Free Ride’ pass so that I could get on Space Mountain before the park closed. She walked with me over to Space Mountain and told me all about Disneyland, including how much she liked working there and what happened to 2,000 Leagues Under the Sea (Yay! Nemo!) We parted ways at Space Mountain and Bryson welcomed me to the ride and ushered me up the FastPass line. At 11:54 PM I sat down in the car for Space Mountain, my last ride at Disneyland.

Space Mountain, by the way, is the fastest roller coaster I think I have ever been on. They can probably get away with it because it’s pitch black so people can’t see how fast they are going or how close they are coming to other pieces of the ride. I mean it, it’s really fast. 35 miles per hour according to Wikipedia. That’s driving speed in Canada.

AAAAnd I’m done. That was Disneyland for me. As it turns out, I probably had more fun in 6.5 hours by myself than I would have if I’d gone with someone else. Of course, I really don’t think it would have been nearly as much fun if it wasn’t for Katie, Sarah, Pat, Mike, Bryson and Lewis (Mike and Lewis were at the gates of the Fantasyland rides that I went on). They really all went above and beyond to make sure that I had a good time, and they were very successful. (If you guys read this, thanks a lot!)

IMG_9514.JPG

So, let this be a lesson to all of you.

If you’re a loner, at least be a nice loner and you never know what good might come of it.

Spillr.com

A silly idea though up by a friend and I one day. Spillr is an anonymous question system where people can ask ANY question they want and other people can answer yes or no. We collect age, gender, city, state, country and hesitation time for each answer and then use the data for fun little statistics. The code base for the question engine ended up being purchased by a company that has used it to power their facebook app.

Hoomai

A personalized version of Spillr. I consider it a third person personality test. Users sign up and then are provided with an encrypted link that they can give to friends. The friends who follow the link are then asked 40 questions about the user. Some of the questions are marked as being personality based and those answers help determine the users’ “projected personality.” Apart from that, it’s also just been fun finding out what percentage of your friends would lend you $100.