Posted by luca
on Wednesday, May 14
Acts As Resource is ready for the imminent Rails 2.1!
I also moved it to GitHub, the new repo is http://github.com/jodosha/acts-as-resource/tree/master, the SVN one is deprecated.
If you enjoyed this post, feel free to recommend me on
Working With Rails.
Posted by luca
on Sunday, December 09
Acts As Resource is ready for Rails 2.0!!
This plugin combines both ActiveRecord and ActiveResource features in one class. It easily allows to deal with a remote REST service or with a local database.
If you want read more visit the plugin page or install with:
$ ./script/plugin install http://dev.23labs.net/svn/rails/plugins/acts_as_resource
Posted by luca
on Wednesday, November 28
Would you use both ActiveRecord and ActiveResource in one class?
Now with Acts As Resource you can!!
Example
About
You can find many informations about Acts As Resource on related page on my blog.
Vote
If you find it useful feel free to add to your favs on agilewebdevelopment.com
Posted by luca
on Wednesday, November 28
Acts As Resource
ActsAsResource combines ActiveRecord and ActiveResource features in one class.
Example
class Carrot
acts_as_resource
self.site = 'http://localhost:3000'
belongs_to :bunny
validates_presence_of :color
validates_uniqueness_of :color
validates_length_of :color, :within => 2..23,
:if => lambda { |c| c.color && !c.color.empty? }
validates_format_of :color,
:with => /[\w\s]+$/,
:if => lambda { |c| c.color && !c.color.empty? }
before_create :please_call_me_before_create
def self.validate
logger.debug("VALIDATE #{color}")
end
def please_call_me_before_create
logger.debug("Ohhh, so you called me..")
end
end
Usage
For convention each operation is local unless specified with :remote flag.
carrot = Carrot.find(23) # => local request
carrot = Carrot.find(23, :remote => false) # => local request
carrot = Carrot.find(23, :remote => true) # => remote request
Carrot.create(:color => 'orange') # => create local
Carrot.create(:color => 'orange', :remote => true) # => create remote
Prerequisites
For 2.0 railists: no problem guys!
For old 1.2.x people you should live in the edge, cause ActiveResource is needed.
Install
Rails 2.1.x
$ ./script/plugin install git://github.com/jodosha/acts-as-resource.git
Rails <= 2.0.x
$ ./script/plugin install http://dev.23labs.net/svn/rails/plugins/acts_as_resource
Uninstall
$ ./script/plugin remove acts_as_resource
Common Issues
Contribute
Repository
git://github.com/jodosha/acts-as-resource.git
Vote
If you find it useful feel free to add to your favs on agilewebdevelopment.com.
Copyright
Copyright © 2007
Luca Guidi -
23 Labs, released under the MIT license