What’s new in Rails 1.2
- Published January 20th, 2007 in Ruby
After announcing that Ruby on Rails 1.2 had finally been released it's time to take a look at one bloody cool feature: ActiveResource.
First, let's recall the usefulness of ActiveRecord. Generate a model and then simply use it like the following
-
Person.find_by_name('mario').last_name => "lopes"
All the calls to the database are hidden and you only get the juice.
Now, imagine a Web Service providing the same funcionality as ActiveRecord does. For instance, upon a certain HTTP GET request it would retrieve the last name. What if you could use it precisely the same way was we did before? Actually, whiy not?
-
Person = ActiveResource::Struct.new do |person|
-
person.uri = "http://api.myremote.com/people"
-
person.credentials :name => "me", :password => "password"
-
end
and you're ready to go. Any CRUD request will summon a HTTP equivalent. For instance, a Delete operation would generate an HTTP DELETE and Create an HTTP POST [1].
What's the point? Using decoupled services (like Web Services) as if they were not decoupled. Apart from the initialization code one would not note that the call was actually being made over the network.
This is quite of an achievement. Swapping between a Web Service and a database backend would be straightforward.
More news will follow up later.




No Responses to “What’s new in Rails 1.2”