Ahhh, technology
I'm writing this using the brand new wordpress app for my new iPhone 3g. Where would I be without this thing!!
By the way... Tap Tap Revenge is a truly great game for the iPhone. And this is my current best.
Putting the green in energy bills
I haven't said much about my current job here, but I'm excited about what I'm doing so I thought I would drop some info. At present (and hopefully for the distant future because I enjoy it that much), I'm working for a small software company in State College, PA called Good Steward Software. Our primary function is creating software for medium to large businesses and government entities to track energy usage and expenditures. I know that may not sound like much fun, but when your company is the best at what they do, trust me... it's fun. Because of our position in the market, we get to push the envelope a bit and run with ideas instead of just maintaining the status quo. That's where I come in.

I was originally hired here to do implementations of EnergyCAP, our main product. But when I mentioned that I'd like to get involved with future web app development, I got my wish. For the past six months or so, I've been managing design and development of a product that will be released in September. I'm excited about it because it's all I've done for six months, and it's going to be fun to see what people think.
I can't go into much, but I'll say this. This product will allow home and small business owners the opportunity to track energy bills. With this information they can answer questions like:
- What is the actual cost of energy is for my home/office?
- How does the weather effect my energy usage?
- Were the new windows I had installed worth the money?
- How does my energy consumption compare to similar properties?
- Just how much Greenhouse Gas am I producing?
And on top of all this, it's going to look great (I like to think of it as the GQ of Energy management), and free for end users.
Sounds good, huh? More soon...
Flexable Flex
As I am writing this post, I am sitting in the auditorium of the EBay Town Hall in San Jose, California. No, I'm not here to try to get my money back on a scam auction I was involved in... (another story, for another time!), I'm here for 360Flex. For the last 3 days, Ryan B. and I have seen some very cool new technology at work. It's called Flex, which isn't really new, since it's at 2.0, but it's becoming evident that as a web app developer, it opens a lot of doors to some things that were either not possible or very painful to do before.
Anyway, we've seen some of the development team from Adobe show off some of the things that they have done, and it's quite amazing. Here's a sample. So I'm seeing some of this stuff and realizing that this could completely redo some of the things that I do. In the hotel last night, I slapped together a Flex front end to a Rails back end web services... and I was able to do it in less than an hour. And I didn't even know what I was doing! And just like that, I've got a rich front end that looks identical on any web browser out there. Super cool. I'll probably stick a post up here in a few days that shows how to do it.
P.S. We also made a stop to a certain company store. more later.
Everyone knows the letdown of a bad recommendation…
A newly released site, known as Smatchy (www.smatchy.com), presents an interesting take on recommendations and could become more of the standard than the exception.
Smatchy’s premise revolves around users answering questions and then calculating 'People Like Me' for users in fourteen different categories. This 'People Like Me' statistic drives almost every feature on the site, linking people together based on how similar they are and not any user-defined criteria. While the math behind this seems to be fairly in-depth, the site has produced a slick interface to navigate all of the options, making everything from figuring out your 'Smatches' to querying the dataset fun.
So how do the recommendations fare? Well, pretty well, to be honest. Especially when you consider a lot of the questions are addictive and fun (unlike a strict ranking system). My favorites ones to answer included:
- I'd rather have a root canal than live in Texas.
- It doesn’t get any better than Where the Wild Things Are.
- I would rather be friends with John Cusack from 'Say Anything' than Matthew Broderick from 'Ferris Bueller’s Day Off.'
For recommendations, you get the choice of either 'Normal' or 'Obscure' methodology. While the Normal are good, the real gems are in the Obscure, where unique books, movies, and music are pulled from user’s profiles based upon your matching. Finally, the Forum makes good use of the system with how well individual authors match up to you being displayed alongside the post.
Ruby on Rails is the power behind Smatchy, and does a good job on handling the extensive database while keeping the navigation fun and easy. Rails development being what it is made it fairly quick and painless to put Smatchy on Rails!
As more and more people latch on to this concept, you could just see a better way to get recommendations and interact with other searchers.
[Note: I was personally involved with the site’s Rails development.]
Ajaxed Select Boxes in Rails
The controller for this exercise includes two methods. One for displaying the main page, and a second for generating the select box. Let's start with the page. We'll call it order_list:
def order_list
end
That was easy. Nothing here. You'll see why in the view.
Now for the second method to populate the second select box:
def fill_orders_box
results = Order.find_all_by_customer_id(@params[:customer_id])
render :partial => 'options'
end
There's a few things here that I wanted to comment on. The first is the find command on the Order model. ActiveRecord does this very slick translation when you use the findallby_ or findby followed by the column to search on. When ActiveRecord sees this, it automagically translates it to the equivalent search string. For instance the above example translates to:
@results = Order.find(:all,
:conditions => ["customer_id = ?", @params[:customer_id])
Now let's be honest... that's pretty cool.
The second thing is the use of the partial. In this example I'm using a partial to fill in the select box option tags. This command makes that happen.
Enjoy the View
The view is where I create the form and put in the first select box, the placeholder for the second select box and the AJAX commands to tie them all together. Here's the code:
<%= javascript_include_tag "prototype" %>
<select id="order[customer_id] name="order[customer_id]">
<%= options_from_collection_for_select(
Customer.find_all_by_customername, "id", "customername") %>
</select>
<span id="order_id_list">
<select id="order_id" name="order[id]"></select>
</span>
<%= observe_field("order[customer_id]",
:frequency => 0.25,
:update => "order_id_list",
:url => {:action => :get_orders},
:with => "'customer_id='+value")
%>
So theres a few things to discuss here. At the top is the javascript_include tag. This is telling the view to use the prototype javascript file in the rails package to handle the AJAX calls. Don't forget this, it's what you call 'important'.
The first select box is straight-forward, but it's filled with another slick rails deal. Optionsfromcollectionforselect takes the first parameter (note the findallby thing again) to get the recordset to fill it with (hence nothing in the controller for this), the id field is next, and lastly the text for the option statement. Very slick indeed!
Next we have the placeholder for the second select box. In this case I used a span, but div will work too. Then I put an empty select box so that it's there from the start, you can leave this out if you want it to appear when you click a customer in the first box. Also worth mentioning here is something Rory said on his site, you can't change the innerHTML of a select box in IE, so that's the reason for the span, we'll change what's in there with the partial.
Now for the AJAX. The last part is the listener. This makes it so the page is always looking for the first select box to change. It looks at the frequency of once ever .25 seconds. When it senses a change, it calls the URL with the included with value as a key and updates the orderidlist span. There's a bunch of magic that happens in the background, but let's face it, that's the best part about rails!
Partial Credit
The last part is the partial. This file is called _options.rhtml. Note the underscore...this is what makes a partial a partial. Because DHH said so.
<select id="order_id" name="order[id]">
<% for order in @results do -%>
<option value="<%=order.id %>" >
<%= order.order_number %>
</option>
<% end -%>
</select>
That's it. Here we generate the select box, loop through the records that are sent from the controller and create a slew of option tags.
So there you have it. As I said before, I'm fairly new to rails and ruby, so if you find flaws in my code (which shouldn't surprise you) please leave a comment and let me know. I hope this helps someone!
