Just A Summary

Piers Cawley Practices Punditry

Initial release of acts_as_resource 18

Posted by Piers Cawley Thu, 25 Jan 2007 12:56:00 GMT

Right. I’ve bundled acts_as_resource up and stuck it on the typosphere SVN server. You can grab it from http://svn.typosphere.org/typo/plugins/acts_as_resource if you’re interested.

It’s currently in what I’d call an all convention, no configuration state – if your resources don’t look pretty similar to the kind of things you get from the resource scaffolding, you’ll probably have some pain, but I expect to rectify that with coming releases. One thing I want/need to do for instance is to allow for ‘relative’ ids in your resource url. For instance, if you’re looking at /albums/10/tracks/982, it’s not the most readable of permalinks… next trick is to allow you to have urls like /albums/because-its-there/tracks/1, ie: the first track on the album ‘Because it’s There’. I’m sort of expecting that you’d do that by doing:

class Album has_many :tracks acts_as_resource :uri_field => :name_dasherized end class Track belongs_to :album acts_as_list acts_as_resource :uri_field => :position, :parent => :album end

However, my first priority is to add some tests (or, more likely,Rspec specifications) so I’ve got some confidence that I’m not breaking things as I go.

Anyhow, go grab the plugin, have a play, let me know what you think.

'acts_as_resource' progress

Posted by Piers Cawley Thu, 25 Jan 2007 09:30:00 GMT

I’m very nearly ready to release acts_as_resource, I just have to pull up and tidy code that’s currently in my working directory’s ApplicationController and we’re laughing. However, I thought you’d like to see what my nested controller looks like.

My first 'acts_as' plugin 7

Posted by Piers Cawley Tue, 23 Jan 2007 17:39:00 GMT

So, you’ve upgraded to Rails 1.2.1 and you’re working on a tool to maintain a database of all the tunes you have in your various songbooks and (eventually) your record collection. You start with:

$ ./script/generate rspec_resource MusicBook title:string author_id:integer \ abstract:text $ ./script/generate rspec_resource Tune title:string composer_id:integer \ abc:text book_id:integer

You decide to come back to composers and authors later, so you set up your models1:

MusicBook.has_many :tunes Tune.belongs_to :music_book

And your routes:

map.resource :music_books do |book| book.resource :tunes end

Problems start here

Being a cautious sort, before you start adding behaviour, you fire up a development server and go and check things with the browser. The /music_books/ stuff works fine, but once you start looking at /music_books/1/tunes things start to get weird; all of a sudden your links aren’t making sense.



Just A Summary