Auto Rest plugin

Plugin details

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.

Websitehttp://code.google.com/p/autorest/ Repositoryhttp://autorest.googlecode.com/svn/trunk Tags Rest LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://autorest.googlecode.com/svn/trunk

For a complete test app, check downloads on http://autorest.googlecode.com/ for a complete sample app. that 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.

Set the routes. AutoRest is currently developed with a maximum 2-level nesting of routes in mind. See http://weblog.jamisbuck.org/2007/2/5/nesting-resources

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).

body
	<%= ar_breadcrumbs %> 
	<%= yield %>
body

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (1 older version) | Last edited by: scott, 8 months ago