Prototyping With Rapid Resource: A Proof of Concept

Posted by Jeremy Voorhis Fri, 04 Aug 2006 01:35:00 GMT

This is still unreleased, but i am toying with controller macros as a rapid prototyping tool for resources. Just add models, .rhtml, .rjs and .rxml templates.

ActionController::Base#define_actions accepts a parameter which specifies the set of actions to be included. The protected methods resource_name, collection_name, resource, find_collection and find_member provide an api which the actions build upon and may be overridden as needed. Actions may also be overridden piecemeal.

Routes


ActionController::Routing::Routes.draw do |map|
  map.resources :entries do |entries|
    entries.resources :comments
  end

  # Install the default route as the lowest priority.
  map.connect ':controller/:action/:id'
end

Controllers:


class EntriesController < ApplicationController
  define_actions :crud
end

class CommentsController < ApplicationController
  define_actions :crud

  protected
    def find_collection
      Comment.find :all,
          :conditions => ['entry_id = ?', params[:entry_id],
          :order => 'created_at'
    end

    def find_member
      entry = Entry.find params[:entry_id]
      entry.comments.find params[:id]
    end
end

11 comments

Sharpen Your Focus

Posted by Jeremy Voorhis Wed, 02 Aug 2006 10:47:00 GMT

If you are excited about Ruby on Rails development and want to better understand the intersection of application design and web architecture, then I am pleased to announce that I will be hosting a workshop in September. Stay tuned for more details.

Posted in Rails, web development, Ruby | no comments

Announcing resource_hacks

Posted by Jeremy Voorhis Tue, 01 Aug 2006 04:02:00 GMT

resource_hacks is a plugin that extends edge Rails’ new restful routes implementation. While the current opinion of the core team is that we should only use member resources with a numeric id, resource_hacks allows Rails to support arbitrary an arbitrary member path. Allow me to illustrate:


  map.resources :entries

gives us the member path /entries/1 where 1 is the value of params[:id]. With resource_hacks, you can still use a numeric id, but also declare an arbitrary member path like so:


map.resources :entries,
  :member_path => '/entries/:year/:month/:day/:permalink'

This gives us the member path /entries/2006/8/1/announcing_resource_hacks rather than /entries/1.

With this routing definition, you may send an HTTP request with the PUT method to update the Entry via EntriesController#update. The same goes for DELETE. The collection found at /entries will not be affected by resource_hacks.

You can install the plugin by running


  $ script/plugin install http://svn.planetargon.org/rails/plugins/resource_hacks

from your application’s base directory.

One final note: I cannot take full credit for this plugin. The basic implementation came from Andrew Grim, PLANET ARGON’s latest developer. Welcome, Andrew!

Posted in Rails | 9 comments

See You at RailsConf Europe

Posted by Jeremy Voorhis Mon, 31 Jul 2006 21:38:00 GMT

This morning, David Heinemeier Hansson addressed Lars Pind’s concern about the lack of buzz surrounding RailsConf Europe. Here are my reasons why you should attend:

The speaker lineup is incredible. If you didn’t make it to OSCON, now is your chance to hear the wise and charismatic Kathy Sierra. Ruby gods PragDave and Jim Weirich – the author of the Pickaxe and the developer of Rake, respectively – will be presenting. David A. Black, author of Ruby For Rails, will also be presenting. Although I am not listing all of the keynotes here, an additional four will be delivered by members of Rails core – Rails core will have a stronger presence than at the American RailsConf.

Another reason RailsConf Europe is worthwhile: Ruby Central. While attending the American RailsConf, I realized how truly hard Chad Fowler and David A. Black worked to ensure that all involved had a great experience. If RailsConf Europe’s American counterpart set any kind of precedent, RailsConf Europe will not disappoint.

Finally, I’ll be delivering a new talk about a topic that I have wrestled with quite a bit lately while working at PLANET ARGON, as well as writing a book for O’Reilly Media. A summary:

Project automation enables development with greater rapidity and fewer errors. Your systems administrator knows this, and many long-standing development projects have accumulated an extensive repertoire of scripts and build tasks. While Rails developers have the industry’s best tools for project automation at their disposal, many of them are unfamiliar with these tools. In this talk, I will explore a diverse set of problems tasks which can be made simpler with good project automation.

In this talk, I will attempt to give a high-level view of what project automation is, why it is necessary, and how to implement it by using Rails’ built-in Rake tasks and Capistrano, how to automate tasks special to your project, and how to deal with one-off cases like digital asset management, or writing a book.

See you in London!

2 comments

What's New in Edge Rails: Restful Routes

Posted by Jeremy Voorhis Mon, 31 Jul 2006 03:03:00 GMT

While I’m no Ryan Daigle1, I do subscribe to the Rails trac RSS feed and decided to speak up after watching this changeset roll in.

simply_restful began its life as a plugin, and at RailsConf, the core team announced that it would be merged into Rails core.

simply_restful has been merged into Rails core. Its functionality seems basically intact, with one minor adjustment: resource names are now pluralized. This means that in your routes.rb file, you must specify


  map.resource :entries

instead of


  map.resource :entry

The same goes for the companion method resources, which allows you to declare multiple resources at once.

In addition to providing clean URLs which respond to multiple HTTP methods, simply_restful also allows you to specify additional actions which respond to certain verbs like so:


  map.resources :comments, :member => { :approve => :post }

In this case, the url /comments/1;approve would be created. The rationale is to use the path to the left of the semicolon for a resource’s identity, and to use the path to the right of the semicolon as a modifier. Frequently this modifier would be an operation that you would perform on the resource, such as approving a comment that requires moderation.

In the plugin version of simply_restful, there was a bug which allowed only one additional action per HTTP method – you could not have two semicolon-style URLs which accepted the GET method, for example. This bug has been fixed.

I have yet to verify whether the pluralization issue affects this incarnation of simply_restful, but this would be a good time to release a plugin of my own that scratches an itch of mine since the plugin was released.

1 While the Rails changeset log is certainly available for everyone to read, Ryan provides a good service for anyone who wants a periodical synopsis of the latest changes, rather than a constant trickle. Thanks, Ryan!

6 comments

How I Learned Ruby

Posted by Jeremy Voorhis Sun, 30 Jul 2006 22:22:00 GMT

This morning after refreshing my blogroll, I noticed that I had received a chain letter. Here is my response.

What was your technical background before you started learning Ruby/Rails?

My earliest flirtations with web development involved Perl and MySQL, and my first professional programming job involved PHP and Microsoft SQL Server. I later moved on to working with .NET on Windows. While Visual Studio was sometimes inescapable, I claimed the Mono platform and Emacs as my development environment whenever I could.

How long ago did you start?

I have programmed professionally since 2003. I have been a full-time professional Rails developer since March 2005.

What were the two most useful resources to you in the learning process (not counting The Agile Book or the Pickaxe Book, which we’ll assume everyone knows about)?

Regarding learning the Ruby langauge, the most helpful resources have been community-based. Ruby Quiz, the #ruby-lang channel on freenode.net, the Ruby Talk mailing list (although I mostly browse the archives), fellow bloggers, and the erratic Poingant Guide to Ruby.

Because the Ruby language has such varied influences, it also helps to understand them as well. Many folks who see Ruby for the first time comment that is looks “Perlish”. On the surface level it bears a resemblance, but my nominal experiences with languages like Scheme and Smalltalk have contributed more to my mental model of Ruby than Perl.

Tell us the story of how you came to learn Rails:

Prior to Rails, I had been experimenting with Nant, NUnit, NHibernate and different approaches to the model-view-controller architecture on .NET. Rails was a natural fit because it encompassed a familiar toolset, but in a smaller, more easily comprehended package.

Three Ruby bloggers to whom you’re passing the baton:

Posted in Rails, web development, Ruby, Languages | no comments

Howto Make simply_restful Useful For Real People

Posted by Jeremy Voorhis Fri, 28 Jul 2006 04:11:00 GMT

For those rare occasions when a numerical sequence is not enough…

  1. Open vendor/plugins/simply_restful/lib/simply_restful/routes.rb
  2. Change line 30 from
    member_path = "#{path}/:id"
    to
    member_path = options.delete(:member_path) || "#{path}/:id"

Now you can specify your routes as follows:


  map.resource :entry, :member_path => 'entries/:year/:month/:day/:permalink'

1 comment

Plugins and the Inflector - A Stopgap Measure

Posted by Jeremy Voorhis Wed, 26 Jul 2006 02:02:00 GMT

While reading through the source of Rails::Initializer, I discovered and confirmed a solution to ordering problem documented at http://www.jvoorhis.com/articles/2006/06/30/plugins-and-the-inflector.

The individual environment files (config/environments/development.rb, et. al.) are loaded before any plugins are loaded, while the last portion of config/environment.rb is loaded after plugins are loaded.

This means that you can declare your custom inflections in those individual environment files. Just be sure that your inflections are shared across all three files. A good solution might be to create config/inflections.rb and require it in all three sites.

Posted in Rails | no comments

Older posts: 1 ... 3 4 5 6 7 ... 18