AutoRest first public release 31/10/2007
Simplify the development of rest based applications by using a generic controller implementation.
Based on scaffold_resource of rails 1.2.3.
With a single call of a class method, includes the default methods for a rest controller
using user-supplied configuration.
Smart defaults are generated for all the missing configuration parameters.
Author
Emmanuel Oga. http://EmmanuelOga.WordPress.com
Usage
For a complete sample app, check the sample app in the downloads.
That app should be extracted to the root of the plugin. The sample app specs covers a great deal of the functionality that would be very difficult to spec without a complete rails app.
By using the ar_spec_scaffold generator, a controller with all the options ready for customize is generated.
The generator usage is the same as scaffold_resource:
ruby script/generate auto_rest ResourceName [optional_field_1:type] [...] [optional_field_n:type]
The optional fields are used only to include them on the migration. This generator produces also
the proper specs on RAILS_ROOT/spec folder. You can use the --skip-rspecing to skip the generation
of rspec-based specs.
Don't forget to:
- have rspec and rspec on rails plugins and have ran ruby script/generate rspec if you wish
to use rspec.
So it uses routes like
ActionController::Routing::Routes.draw do |map|
search_opt= { :search => :get }
map.resources :zones, :collection => search_opt do |zone|
zone.resources :customers, :name_prefix => "zone"
end
map.resources :customers, :collection => search_opt
end
- For the integrated ferret support, you should put a :search => :get route
on the collection of resources, just like i did above. Also include acts_as_ferret
plugin and acts_as_ferret on the model class of the resource.
- Set the proper resource relationships on models (has_many / belongs_to)
- Create an application layout. If you include a call to ar_breadcrumbs in your layout, breadcrumbs will be available (i would say this is only usefull when you are working with nested resources).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd"> <html><head><title>AutoRest Test App</title></head>
<body>
<%= ar_breadcrumbs %> <hr/>
<%= yield %>
</body>
</html>
- Configure each controller at your heart's content :)