REST with Rails: Four Weeks and Counting
Just a reminder that REST with Rails is only four weeks away. If you’ve been on the fence, we encourage you to sign up. We have to close registration real soon so we can make final preparations for the class.
There are a couple of things I’d like to mention about the class.
For Beginners and Intermediate Developers
This is not a class for advanced Rails developers unless you’re also new to REST (which would be unusual).
If you’re new to Rails, or have been working with it for a while and are ready to learn what REST is all about, then join us! We designed this class to have a relaxed, non-intimidating atmosphere so everyone can feel comfortable and learn a lot at the same time.
PayPal Not Required
We’re using EventBrite to handle registration for us. Their integration with PayPal accepts both credit cards and PayPal payments. You do not need a PayPal account to sign up for the class. You can quickly and easily pay with any credit card.
However PayPal doesn’t make the credit card link entirely obvious and it’s led to some confusion.
At the bottom of the order form, click anywhere the credit card images (or on the PayPal logo – it doesn’t actually matter):

Then, once you’re on the PayPal site, ignore the “Log In” form and simply click the Continue link* (circled below):

If you still have trouble signing up, be sure to let us know (drop us a comment here or send Jeff an email).
Mike Gunderloy interviewed by FiveRuns
Don’t miss a great interview with Mike Gunderloy as part of the FiveRuns TakeFive interview series.
Mike was an awesome .NET developer and writer (and also wrote one of the most popular .NET news blogs ); nowadays he’s an awesome Rails developer and writer.
In our small-but-growing convoy of those who’ve made the transition from .NET to Rails, Mike has been a true pioneer.
Whether you originally hail from Microsoft development land (like I do) or not, I highly recommend his notes on all things Ruby, Rails, and beyond .
Neal Ford on Complexity
Neal Ford has one of the best-written explanations of system complexity that I’ve ever read.
Not only is the substance of what he’s written really great, but also the manner in which he wrote it: concise and to the point, without resorting to a lot of words, analogies, or unnecessary explanations.
Which demonstrates his point about software complexity.
Awesome.
Using Routes Instead of Custom REST Actions

Suppose you’re trying to be a good Rails developer and use RESTful routing wherever possible in your application. Using the ever-present blog example1, you might implement your PostController’s index action like this:
def index
@posts = Post.all unless request.format.rss?
respond_to do |format|
format.html # render posts.html.erb
format.xml { render :xml => @posts }
format.rss { @posts = Post.all(:limit => 10, :order => 'created_at desc') }
end
end
In other words, for HTML and XML clients, we return all the posts, formatted accordingly. For RSS readers, we only give out the 10 most recent posts2.
Without doing anything special, this url:
/posts.rss
will automatically use /app/views/posts/index.rss.rxml (which we have to write) to generate our RSS data feed.
But I Knew That Already
Ok, but suppose you’re converting an existing site, and your readers already grab your feed at this url:
/posts/feed
Now, our code won’t work. Rails will try to call the show action, using feed as an :id parameter. Not good.
At this point, the easiest thing to do is to add a custom action to your controller:
def feed
@posts = Post.all(:limit => 10, :order => 'created_at desc')
# render default template
end
Rails will automatically find a template named, say, app/views/posts/feed.rxml and use it generate the feed.
But those who know me, know that I despise custom actions. Yes, once in a blue moon I have to use them. But in this situation, I prefer to use a more elegant solution: routes.
Ok, But Did You Know How To Do This?
We need to support /posts/feed as our url for RSS feeds. Remember that Rails routing allows us to route any url we want into any controller action we want. So somewhere above the map.resources :posts line in our routes.rb file, we do this3:
map.feed 'posts/feed', :controller => 'posts', :format => 'rss'
And now if you go to /posts/feed, your glorious index action will be called and will respond as if an RSS client has made the request.
Cool, no?
1 At our workshop, we will build something more interesting than a blog.
2 We’ll also learn how to use named scopes to simplify this kind of code.
3 Even in development mode, you might have to restart your local server (mongrel or webrick or thin or whatever) to get Rails to pickup your routing changes.
Ready to learn more about RESTful development? Register now for REST for Rails before the seats are all gone.
Finding Good Rails Training in Your Area
I just wanted to take a quick moment to recognize the Ruby On Rails Workshops site. It’s provided by Geoffrey Grosenbach. It’s been around for as long as I can remember (ok, probably since 2006, I guess?), and always lists the top-notch events that are happening in the Ruby/Rails world.
I really like the way you can filter the results by country. Or use the calendar to quickly get a monthly listing (and even hover over a date in the calendar to see what classes are on that day).
For example, here are the workshops coming up in the US.
Thanks to Geoffrey for continuing to maintaining the site and continuing to make it available as a service to the Ruby and Rails communities.
Ready to learn all about REST with Rails? Our next workshop is coming up fast (Oct 4, 2008), so register now before all the seats are taken.


