Insights on Ruby, Git, jQuery, Cappuccino, WordPress, Debian and OS X. Please subscribe if you find something useful!

Cappuccino On Rails

Posted: January 12th, 2010 | Author: Jerod | Filed under: Cappuccino, Projects | Tags: | Comments

I’m happy to announce the release of CappuccinoResource (CR), a library dedicated to interfacing between a Cappuccino front-end and a Rails back-end.

CR should feel very familiar to Rails developers. Its interface is akin to ActiveResource and it borrows heavily from the (very good) ObjectiveResource library for the iPhone.

All basic CRUD operations are supported, and you can perform advanced finds with arbitrary parameters. A brief example of fetching a record, modifying it, and saving it:

var post = [Post find:@"42"];
[post setTitle:@"Why X is Better than Y"];
[post save];

Check out the README on the project’s page on GitHub for more details and usage examples.

Live Demo

I also created a demo application which is a simplified clone of OS X’s Address Book. The demo is live on Heroku. Check it out. The source for the demo is also on GitHub.

If you’re a Rails developer waiting for a good opportunity to try out Cappuccino, there’s no better time than now.

If you’re a Cappuccino developer looking for an easy-to-use, powerful back-end for your applications, Rails might be the answer for you.

CR is a young project, but it drives one of my client applications that is production-ready (albeit not deployed), so I believe it is ready for prime time. Please try it and let me know how it goes.

Fork, report issues, et cetera.


Dead Simple Rails Deployment

Posted: May 31st, 2009 | Author: Jerod | Filed under: Git | Tags: , , | Comments

Deploying a Rails app used to suck. Reverse proxies, Mongrel clusters, Monit, etc. Capistrano helped out a lot (once you set it up the first time), but all in all the process was still pretty painful.

Thankfully, a couple of technologies have come along and made my deployment process a whole lot easier.
Read the rest of this entry »


Date Range Goodies in Rails

Posted: August 27th, 2008 | Author: Jerod | Filed under: Ruby | Tags: | Comments

Sometimes Rails just blows me away, and it just happened a few moments ago. When it comes to dealing with dates and their formats between different databases, Ruby, time zones, etc, etc…it can get pretty nasty. I can’t believe the amount of help Rails delivers in this arena.

Let’s assume I’m trying to track phone calls across time ranges; daily, monthly, yearly. This can usually become troublesome as I’ll have to query the database to find only records inside those ranges. I will spare you all the lame ways I tried to implement this by hand and just show you the code of how to create a named scope and call it using Rails 2.1.0.

# in call.rb
class Call < ActiveRecord::Base
  named_scope :by_month, lambda { |d| { :conditions  => { :date  => d.beginning_of_month..d.end_of_month } } }

What this does is create a new scope called by_month that lets me query the database…by month :) and pass in a Date object as a single parameter. Rails/ActiveRecord will take the Date object and pass it to the lambda block, which calls the two Rails helpers ( beginning_of_month and end_of_month ) to find the date range for the month my Date object is in. It then queries the database using that date range!

Awesome.

Now I can access the records I want like this:

this_months_calls = Call.by_month Date.today

And Rails will return all the calls that were recorded during the current month. Love it.


Rails + Screen = Awesome

Posted: July 24th, 2008 | Author: Jerod | Filed under: Ruby | Tags: , | Comments

Unix’s screen utility is like pow-pow-power wheels for remote shells. I created a short screencast awhile back showing how to use screen to ease your Rails development.

The server that was hosted on is gonezo so I am reposting it here for your enjoyment:

Link to Embedded Screencast


Rails: Nested Layouts

Posted: June 20th, 2008 | Author: Jerod | Filed under: Ruby | Tags: , , | Comments

Sometimes one layout (application.html.erb) just doesn’t cut it, but you don’t want a separate layout for each controller in your app. You can use the following technique to nest your Rails app’s layouts:

In this example, there are two controllers for a simple todo list manager; lists and tasks

#  application.html.erb
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <title>TODO >> <%= yield(:title) || "Get things done!" %></title>
    <%= stylesheet_link_tag 'todo' %>
  </head>
  <body>
    <div id="container">
      <p style="color: green"><%= flash[:notice] %></p>
 
      <%= yield :main%>
    </div>
  </body>
</html>

The key here is the yield :main on line 16 which means we can use content_for to put our nested layouts’ output inside the yield. Here is the lists layout:

# in lists.html.erb
 
<% content_for :main do %>
  <div id="lists_container">
    <%= yield %>
  </div>
<% end %>
<%= render :file  => "layouts/application.html.erb" %>

Now your view gets rendered inside this layout’s yield and its all good in the hood. Cheers!