Posted almost 3 years ago by Philip Ingram
In my rails app, I’m using Active Resource to ‘talk to’ another Sinatra app that is using Datamapper as it’s ORM. (To learn more about ActiveResource, check out the railscasts 94/95
I didn’t see any google fodder when i started this so I just wanted to report that it works like a charm.
The magic lies in responding with a to_xml call in Sinatra. How that data is compiled doesn’t seem to matter.
Active Resource follows the RESTful Resource mentality. By this, I mean, that when you are expecting more then ONE record back, you have to use an INDEX type action.
This kind of blew me away as I didn’t expect it to be that way.
Let’s pretend you wanted to find all posts created today.
In Active RECORD you would do:
Post.find(:all, :conditions => {:created_at => Date.today})
in Active Resource it would be:
Post.find(:all, :params => {:created_at => Date.today})
and in your Sinatra app, you would have the code:
get '/posts.xml' do
@posts = Post.all(:created_at => params[:created_at])
return @posts.to_xml
end
If you just needed to get the title of ONE post, you would fetch just that record from say /posts/:id.xml for example.
Keeping Subscription dates tidy during February and Leap years
Testing ActiveResource - Basic Tutorial
Active Resource to Sinatra DataMapper backend
ArmRest and the tale of the No Schema Scheme
Textmate Ruby 1.9.1 and rvm - the facts
Easiest Postgres Install Ever - Mac Edition
Two Questions to Help Decide Between RDBMS, MongoDB or CouchDB
Testing Rails 3 - Just the Facts
Acts_as_snook - Creating an admin panel
Top 10 Movies of this Decade... Rebuttal
Thinking_Sphinx - Easy Setup Tutorial