Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

By Peter Cooper / June 8, 2006

Pastie

Pastie is a new code pasting system developed by Josh Goebel. It has a 37signals type quality to it. It’s clean, quick, and does just what it says it’ll do. It colors your code and is just generally slick, pretty, and a fine piece of work. Josh also claims it’s less than 200 lines of Rails. Let’s hope the source gets released! Read More

By Peter Cooper / June 8, 2006

Ryan Daigle reports that the latest ‘edge Rails’ has a cool new feature that lets you specify find conditions more logically. For example:

Post.find(:first, :conditions => ['status = ? and active = ?', 1, 1])

.. becomes:

Post.find(:first, :conditions => { :status => 1, :active => 1 })

I’ve accidentally tried to use this style before, and am glad it’s now an approved part of Rails. If you’re running edge Rails, you should have access to it as soon as you update, otherwise wait for Rails 1.2 :)

If this tickles your fancy, you might also want to check out ez_where by Ezra Zygmuntowicz that lets you do insanely cool stuff like:

articles = Article.ez_find(:all, :include => :author) do |article, author|
article.title =~ "%Foo Title%"
author.any do
name == ‘Ezra’
name == ‘Fab’
end
end

Yes, abstraction rules. Read More

By Peter Cooper / June 8, 2006

It’s quick and easy (to do, not necessarily to parse!).

Step one: Install the FeedTools gem with gem install feedtools

Step two: Use the following code:

require ‘rubygems’
require_gem ‘feedtools’

feed = FeedTools::Feed.open(‘http://www.petercooper.co.uk/index.rdf’)

puts “Feed title is #{feed.title}”

feed.items.each do |item|
puts “#{item.title} – #{item.link}”
end

Step three: Learn more with the official tutorial and API documentation.

Step four: You are now the King of all feeds. Read More

By Peter Cooper / June 8, 2006

From http://rails.co.za/articles/2006/06/03/using-railscron:

RailsCron, by Kyle Maxwell, ‘is a way to run background tasks using your Ruby on Rails environment.’ You could arguably do what ever you want to do in the background via running a crontab that executes the script/runner, but RailsCron enables you to do it all from ruby code, and seeing as it is an ActiveRecord object, you can manipulate it as such from your application.

Rails Cron isn’t the be-all and end-all of background task automation, but it can provide a useful crutch to lean on in some situations. If you need to send regular mails to users, etc, give it a look. Read More

By Peter Cooper / June 7, 2006

Ruby Inline is an analog to Perl’s Inline::C. Out of the box, it allows you to embed C/++ external module code in your ruby script directly. By writing simple builder classes, you can teach how to cope with new languages (fortran, perl, whatever).

I downloaded it (simply download the gem and install it) and tapped out the following code, and it worked just great:

require ‘rubygems’
require_gem ‘RubyInline’

class << self
inline do |builder|
builder.c "
int dummy(int input) {
int i = 1;
while (input >= 1) { input–; i *= 2; }
return i;
}
"
end
end

puts dummy(8)

This works a treat on OS X. Read More

By Peter Cooper / June 7, 2006

Radiant-1

A lot of people have considered developing a content management system in Rails over the past year, but few attempts have turned into something usable. Enter Radiant CMS. It’s not finished yet, but it provides a good example of a Rails application and is available now via SVN. If digging through Rails source code is the way you learn best, enjoy! Read More

By Peter Cooper / June 6, 2006

The forum set up for the Rails Recipes book has a section where readers can write their own Rails recipes. Some of them are pretty good and would have been good contenders for the book. Here are some of them:

By Peter Cooper / June 6, 2006

Pagination in Rails is good, but it can lack flexibility in many situations. At that point it’s time to roll your own. However, Phil Bogle and Laurel Fan came up with a solution they call paginate_by_sql that can solve some of the custom pagination problems. This needs to become a plugin.

I’m reposting their code here simply because I like to see syntax coloring :) Read More

# paginate by sql
# http://thebogles.com/blog/2006/06/paginate_by_sql-for-rails-a-more-general-approach/
# added support for sql with arguments
# added a :count option for passing in either a Integer count or count query.
module ActiveRecord
class Base
def self.find_by_sql_with_limit(sql, offset, limit)
sql = sanitize_sql(sql)
add_limit!(sql, {:limit => limit, :offset => offset})
find_by_sql(sql)
end

def self.count_by_sql_wrapping_select_query(sql)
sql = sanitize_sql(sql)
count_by_sql("select count(*) from (#{sql})")
end
end
end

class ApplicationController < ActionController::Base
def paginate_by_sql(model, sql, per_page, options={})
if options[:count]
if options[:count].is_a?

By Peter Cooper / June 6, 2006

Rubyclasses

These are a few years old now, but they can still come in useful. Here are some useful graphs of Ruby’s class hierarchies for data types, IO, etc. Read More

By Peter Cooper / June 6, 2006

This cool Ruby cheat sheet quickly runs you through.. reserved words, syntax rules, escape characters, regular expression characters and formats, file mode strings, special variables, expressions, operations, built in classes, and more. Extremely useful to beginners and advanced Rubyists alike. Read More

By Peter Cooper / June 6, 2006

Watir

I can’t test this as I’m not a Windows user, but Watir looks very interesting. It’s a testing tool that runs with Ruby on Windows and it controls an instance of Internet Explorer and lets you test any web sites or applications you want programmatically. It’s like integration tests but for any site, and from IE. There’s a sample test if you want to see how a basic test comes together.

Of course, if you want something that’s cross platform and cross browser, Selenium will be more your cup of tea! Read More

By Peter Cooper / June 6, 2006

Rcookbook
Inspired by the legendary (amongst Perl programmers anyway!) Perl Cookbook, comes the Ruby Cookbook. It has the equivalent examples from the Perl Cookbook but in Ruby form, of course. The basic sections are mostly complete, although some of the later sections are barely covered yet. Still, if you want to see the basic recipes for dealing with strings, numbers, dates and times, arrays, hashes, file I/O, process management, and so on, it’s a cute little resource. Read More

By Peter Cooper / June 6, 2006

Rav
There’s been talk about producing something like this in the Rails community, and it seems someone has finally done it.. a Rails Application Visualizer. Simply run a rake task and it produces a graphic showing your models and how they relate to one another. It requires the GraphViz library to run, and is only in its early days. Looks promising though! Read More

By Peter Cooper / June 6, 2006

You might have noticed this blog has nice, syntax colored code excerpts, as does Code Snippets. Jim Morris looks at how you can pull this off in a few different ways. One quick and easy way is to use syntax.carldr.com, a Web site that converts any Ruby code you paste into the correct syntax colored HTML. Currently I use TextMate and an external script using the syntax gem, but might use that site instead as it’s easier! Read More

By Peter Cooper / June 5, 2006

Rail Mail is a Rails plugin by Scott Fleckenstein that stores copies of any mail that your Rails application sends, and provides an interface to view it. Read More

Recently Popular Posts