Seriously @steam_games, I’m ab…

Seriously @steam_games, I’m abroad, why don’t you let me buy games from you with my verified credit card?

Posted in Tweets | Leave a comment

Droid certainly does. Just had…

Droid certainly does. Just had a skype conversation where the other user used her phone as the webcam. Pretty slick

Posted in Tweets | Leave a comment

Auto_Complete Goodness

Zolio has been consuming a large part of my life this summer and I’m happy to say that it’s ready for testing. A few accounts are being generated and sent out to testers today who will hopefully find ways of breaking the site so I can fix it.

The last feature that needed to be added is a way to create classes, assign teachers and students to those classes, create assignments, and have students post files to those assignments.

While this seems to be like quite an undertaking, Rails makes it really easy to do. What was interesting; however, was how the student goes about attaching files:

A student is enrolled in a class. A school has many classes. Classes have many users. This sort of logic grows out of control very quickly. Specifically for the file upload, a user has to specify which class he is attaching his file to; however, he is only allowed to attach files to classes within his school that he is enrolled in.

Because I love autocomplete so much, and because Rails makes it so easy to implement, I chose to use it for helping the user select what class to attach his file to. I could have used a drop down, but they seem so inelegant these days.

Autocomplete works by querying a specific table for a column. As text is typed in the box, javascript is used to keep making calls to the database to narrow down the list. I quickly realized I may run into a problem as we actually need to query two tables.

In one table, we have a list of classes. This list contains the name of the class as well as the school it is associated with. In another table, we have a list of user IDs and the class IDs they are associated with. These class IDs relate to the IDs of the classes in the class table (the one with the name and school). What we needed to do is somehow retrieve a list of the classes only the student is associated with, but retrieve it as a name, not the ID of the class. Pat Shaughnessy’s Auto_complete to the rescue:

In my controller, I have the familiar action for auto_complete:

	auto_complete_for :subject, :name do |list, params|
		list.by_user(params[:uid])
		end

Notice, it’s list.by_user which is a new named scope. Now, in my model I have

	named_scope :by_user, lambda{|user_id|{:include=>:users,:conditions=>["subjects_users.user_id=?", user_id]}}

This runs a join on the tables and finds us the classes (by name) associated with the user through the class ID pivot.

Really fun stuff

Posted in Development, Work | Leave a comment

Of course, the only time I’ve …

Of course, the only time I’ve ever called a chip company to complain about freshness, they’re in a meeting about how to better satisfy me…

Posted in Tweets | Leave a comment

Someone please make a poster o…

Someone please make a poster of this and then promptly sell it to me: http://bit.ly/bFsXEZ

Posted in Tweets | Leave a comment