Well, I spent the second half of today (and >4 hours at Farmer Boys) working on my Whirlfood project in Rails and made a surprising amount of progress. Took some time to start to get used to the Rails methodology and the Ruby language syntax, but I think I’m in pretty good shape now.
Got to admit, I’m starting to like Rails for rapid development. After 2 days, I feel like I can build a simple web app almost as quickly as I can using C#. Which completely amazes me. Of course, there are lots of complex things and specialized functions that I still don’t know how to do in Rails, but still, I’m pretty stunned. In a good way.
I’ve gotten pretty comfortable using generators (a great idea) and then writing my own MVC stuff and doing custom db:migrate scripts to build models with complex relationships. Got the site set up using the Authlogic plugin to handle user sessions, registration and authentication. Used OAuth to write the page flow system to get the tokens and then store them as part of the user model for future usage. Learned REXML to parse the responses from the Foursquare API for user history, then created an import helper to turn Foursquare Venues into my internal Places model (while maintaining a strong reference to the foursquare id, to avoid duplicate creation).
Then I implemented the two major workhorse models used in Whirlfood — visits and ratings. Visits were pretty easy, they are simply many-to-many model with a timestamp to associate users with places and times (the equivalent of Foursquare’s checkin). Ratings were slightly more complex because they express the concept of “would you go back?” and are many-to-many between users and places, but don’t repeat every time the user visits. Would be pretty annoying if you got asked if you like Subway every time you went there for lunch… so when the rating occurs, you’re only asked to rate places that you visited but have never rated.
Additionally, the ratings controller was a little different because it needed to handle AJAX saves and responses so that a full page of new places can be rated without page reloads. Have to admit, the Rails way of doing this is pretty fantastic and foolproof…
Finally, I did some general controller workflow tweaking. For instance, when your new history is imported there are two possibilities: a) you have new places to rate or b) nothing new to rate. So depending on that case, the user will be redirected to the ratings controller or simply sent back home with a nice “nothing to do” notice. The flash[:notice] concept is another great idea that simplifies this very common function.
Also, in the import process, the import helper will only save new places if they fall into categories that the system knows about. This is because we want to filter out the noise of places like work, home and airports. To accomplish this, the Category model has aliases for each of our location providers (Foursquare, Gowalla, Facebook Places) that translate each of their proprietary category names into our common category system. And if a category is unrecognized, we simply don’t import that place.
So, the interface is pretty ugly right now, but the core integration functionality is completed. A new user can sign up, connect with Foursquare, import their checkin history, and rate their places. I even added a neat google map to the places show view.
Next up: need to build friends and version one of the actual recommendation system. And maybe spend a little time making the UI look nice. Then, I’ll need to spend some time working on the niceties like sending out a “Welcome to Whirlfood” email upon registration, for instance.
- BROWSE / IN TIMELINE
- « Learning Rails – Day I
- » Quickie: Learning Ruby on Rails Series
- BROWSE / IN ruby on rails
- « Learning Rails – Day I
- » Quickie: Learning Ruby on Rails Series
COMMENTS / 5 COMMENTS
Luke Chadwick said on Aug 28 10 at 3:52 pmGreat to hear about your first steps using Rails.
If I can make one suggestion – REXML has really been surplanted by faster XML parsers such as nokogiri or libxml
SPEAK / ADD YOUR COMMENT
Comments are moderated.
