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

Author Archives: Peter Cooper

By Peter Cooper / July 21, 2006

Authorizationplugin

The “Authorization plugin” is an interesting plugin for Ruby on Rails that provides role based authorization for your app. It’s particularly interesting because it includes some ‘English-like’ dynamic methods that can use the defined roles. For example, user.is_fan_of angelina and angelina.has_fans? where ‘fans’ are defined in the roles table. Also look at the code example in the graphic above.

You can also do things like user.is_eligible_for_what (returns an array of authorized objects on which the user has the ‘eligibile’ role) and user.is_moderator_of?(group) (returning true or false if the user has the moderator role upon group). Powerful stuff!

The latest version was released just a few days ago so it should all be ready for full Rails 1.1 goodness. Read More

By Peter Cooper / July 20, 2006

Rored

RoRED is a new Ruby / Rails IDE for Windows by Marcus Oblak.

I don’t run Windows, but it appears to have easy hooks for the dev server, console, and breakpointer built in, as well as easy ways to navigate through methods and models. It also features macro recording and playback, bookmarking, persistent layouts, and Ruby and RHTML syntax highlighting. Read More

By Peter Cooper / July 20, 2006

Scott Raymond has written a useful article showing the thinking behind his refactoring of IconBuffet.com from an action-heavy URL scheme to a REST based URL scheme.
The application behind IconBuffet.com, a royalty-free stock icon store, went from 10 controllers and 76 actions to 13 controllers that more closely followed the models involved, and 58 total actions. Most of the new actions are uniform and match to the new Rails methodology of mapping HTTP verbs (GET, PUT, POST, DELETE, etc.) to Rails controller actions. You can learn more about this structure from David Heinemeier Hansson’s slides (PDF) from RailsConf, or watch the video of his keynote presentation. Read More

By Peter Cooper / July 20, 2006

Juggernaut

Alex MacCraw has been working on a great plugin called Juggernaut, and has now made his first public release:

The Juggernaut plugin for Ruby on Rails aims to revolutionize your Rails app by letting the server initiate a connection and push data to the client. In other words your app can have a real time connection to the server with the advantage of instant updates. Although the obvious use of this is for chat, the most exciting prospect is collaborative cms and wikis.

Basically, your view will contain a hidden piece of Flash that opens up a socket connection to a socket server that your Rails app can then interact with. Read More

By Peter Cooper / July 20, 2006

Railsgraffle

Other than being a new Rails-based site developed during the Summer of Rails, Graffletopia is a great resource for stencils for OmniGraffle, the OS X diagramming and charting app. One of the newest stencils on there is a “Ruby DB modelling” stencil that should help you lay out your models in a neat, easy to edit, way. The author notes:

This is a semi-complete version of a Ruby on Rails way to model a database. The table objects include a space to enter in the declarations that you are considering placing in your model files. I have included a list of reminders of the things that would go into the model declarations towards the right. Read More

By Peter Cooper / July 19, 2006

Remote-Ma128Ga

This one is for Mac users only..

Tim Burks has put together a guide on how to use your Apple infra-red remote from Ruby at RubyCocoa.com. And, as an aside, RubyCocoa.com is a great resource if you’re interested in using the Cocoa framework from Ruby. Read More

By Peter Cooper / July 19, 2006

Railsstats

Shane Vitarana has launched a new Rails plugin called Rails Stats. It’s a graphical version of the rake stats statistics. It generates graphs showing information about your application, and is powered by Geoffrey Grosenbach’s great Gruff Graphs plugin.
Install like so:

script/plugin install http://shanesbrain.net/svn/rails/plugins/rails_stats

And then load /rails_stats on your running Rails application. More info here. Read More

By Peter Cooper / July 17, 2006

Mrguid

Mr. Guid is a Ruby GUI Debugger by ‘Mitchell’. It uses GTK+ so it’s cross platform (Windows, Linux, OS X) and it can even work remotely over a network. Otherwise, it has all the features that the standard Ruby debugger has, just in GUI form. Read More

By Peter Cooper / July 15, 2006

In the recent 19 Rails Tricks Most Rails Coders Don’t Know article, I recommended the use and development of engines to implement common functionality in Rails applications. I simply provided a link to the Rails Engines site and left it at that.

However, Joe France has put together a bumper tutorial on how to create a Rails Engine from start to finish, so now there’s no excuse not to give it a go! Joe holds your hand the whole way. Read More

By Peter Cooper / July 15, 2006

Bruce Williams tries to solve the problem of multiple parameter types in Rails. For example, an action may accept dates via a parameter, but dates may be supplied in many forms. A ‘date’ parameter might arrived as if from a date_select helper, or might even be typed in directly by a user, or be pulled from a database. Rather than use before_filters to check parameters and normalize them, Bruce suggests that it should be possible to add basic conversion tools to certain data types so that all data is normalized by the time it hits your controllers.

Bruce provides a simple example to demonstrate how two different types of date could be prenormalized:

ActionController::Base.add_param_type ‘date’ do |value|
case value
when String
Date.parse(value)
when Hash
Date.new(Integer(value['year']), Integer(value['month']), Integer(value['day']))
end
end

His ideas are available in a plugin called param_types. Read More

By Peter Cooper / July 14, 2006

Active Merchant is a payment processing library for Rails developed by the geniuses behind Rails powered e-commerce system, Shopify. It’s under active development with support for different payment processor gateways being added regularly. So far it supports:

  • Moneris
  • Authorize.net
  • TrustCommerce
  • LinkPoint
  • Psigate

They want to integrate with WorldPay and ChronoPay next. The syntax for using Active Merchant and its descendent classes is ridiculously easy, so check it out (code examples viewable there). Read More

By Peter Cooper / July 13, 2006

There are many scenarios where you might want the same controller action / method in your Rails application to perform multiple functions. For example, a wizard with multiple steps or a single form with multiple-stage AJAX calls. What you want to do is provide a ‘context’ to the specific request and have the controller handle that in some different way.

Until now, one way to do this would be to use a parameter on the URL (e.g.: http://yourapp/post/show/1?stage=something_here) and then simply branch the logic based on the parameter. Bruce Williams saw an opportunity to make things a little better, and has developed in_context. Read More

By Peter Cooper / July 13, 2006

Action Messenger, by Trejkaz Xaoza, is a basic wrapper around Ruby’s xmpp4r Jabber library that makes Jabber instant messaging services directly available to Rails applications. (Jabber is an open, XML specification and framework for instant messaging. Google Talk uses it, for example.)

It’s still in its infancy and currently only supports basic message sending and receiving of messages, but with instant messaging rapidly merging into the plans of many Web applications, it’s a good start. If this sort of functionality is on your wishlist, check it out. Read More

By Peter Cooper / July 13, 2006

Oneliners

Perl is particularly well known for its one-liners from the command prompt, but Ruby is pretty adept at it too. David P Thomas has put together a collection of about 100 Ruby one-liners in a single text file for us all to enjoy. Read More

By Peter Cooper / July 12, 2006

Scrapi

The indefatigable Assaf Arkin has done it again by developing a new Ruby HTML scraping toolkit, scrAPI. Peter Szinek recently wrote a popular article about scraping from Ruby using Manic Miner, RubyfulSoup, REXML, and WWW::Mechanize, but none of these are as immediately useful as scrAPI.. so why?

scrAPI lets you scrape from HTML using CSS selectors. For example, here’s Assaf’s example that defines scraper objects that can scrape auctions from eBay:

ebay_auction = Scraper.define do
process "h3.ens>a", :description=>:text,
:url=>"@href"
process "td.ebcPr>span", :price=>:text
process "div.ebPicture >a>img", :image=>"@src"

result :description, :url, :price, :image
end

ebay = Scraper.define do
array :auctions

process "table.ebItemlist tr.single",
:auctions => ebay_auction

result :auctions
end

Now that the objects are set up ready to scrape, you can put them into action like so: Read More

auctions = ebay.scrape(html)

# No.