Trying out ActiveResource in 3 minutes

Recently I started using ActiveResource to talk to a RESTful controller (which is also done in Rails 2). It is very nice and simplifies a lot. With Rails 2, out of the box you can create a sample RESTful server and client in 3 minutes:

Server:

>> rails test_server
>> cd test_server
>> script/generate scaffold Account name:string balance:integer
>> rake db:migrate
>> script/server
-- hit localhost:3000 with a browser and create some accounts

Client:

>> rails test_client
>> cd test_client
-- create app/models/account.rb with the following:
class Account < ActiveResource::Base; self.site="http://localhost:3000";end
>> script/console
>> acc = Account.find(1) #script/console is now your text-based client :)

Voila! That’s all you need to try out the different methods on ActiveResource.

2 Responses to “Trying out ActiveResource in 3 minutes”


  1. 1 JoshG Feb 12th, 2008 at 10:41 pm

    RPC!! Run away, run away!

    Services != Distributed Objects. It’s not about exposing your domain model to consumers of the service layer (probably unavoidable in Rails due to the fact that your domain model is also exposed to the database - or vice versa).

    I know you’re just playing around for learning but the time taken to create useful services is not in the tool. Mind you, this is a good tool for incremental service build out in a rapidly changing environment.

  1. 1 Services != Distributed Object at Deterministic Musings Pingback on Feb 14th, 2008 at 7:14 pm
Comments are currently closed.