Alexander, here is the way we followed to test RestfulX on the whole
Spree application :
# clone Spree repository
git clone git://
github.com/railsdog/spree.git spree
# copy database.yml.example to database.yml
cd spree
cp config/database.yml.example config/database.yml
# generate Spree rails project
rake db:bootstrap
# install the restfulx gem
sudo gem install restfulx
# edit config/environment.rb
vim config/environment.rb
# add the lines bellow :
# RAILS_GEM_VERSION = 'x.x.x' unless defined? RAILS_GEM_VERSION
(here: x.x.x = 2.2.3)
# config.gem "restfulx"
# run the rx_config generator
./script/generate rx_config
# upadate schema.rb
rake db:schema:dump
# next steps are only for existing Rails application
# modify /usr/local/lib/ruby/gems/1.8/gems/restfulx-1.2.4/lib/restfulx/
rails/schema_to_yaml.rb because of a nil object exception => l.87 and
l.90
# change : "last_in_array_fix = last_in_array_fix.gsub(', ','')" to
"last_in_array_fix = last_in_array_fix.gsub(', ','') unless
last_in_array_fix.nil?"
# and : "schema << " - belongs_to: [#{belong_tos}]\n"" to "schema << "
- belongs_to: [#{belong_tos}]\n" unless last_in_array_fix.nil?"
# generate model.yml from schema.rb
rake db:schema:to_yaml
# Modify the ActionScript model cause Belong_tos don't comply with the
Ruby model.
# Change the generated file model.yml (l. 162) => "- belongs_to:
[group]" to "- polymorphic: [group]"
# create the restfulx scaffold for flex app
./script/generate rx_yaml_scaffold --flex-only
rake db:refresh
# Create the following files in app/flex/spree/models :
# - BillAddress :
#package spree.models {
# [Resource(name="bill_addresses")]
# [Bindable]
# public class BillAddress extends Address {
# public static const LABEL:String = "firstname";
# }
#}
# - ShipAddress :
#package spree.models {
# [Resource(name="ship_addresses")]
# [Bindable]
# public class ShipAddress extends Address {
# public static const LABEL:String = "firstname";
# }
#}
# - CreditcardPayment :
#package spree.models {
# [Resource(name="creditcard_payments")]
# [Bindable]
# public class CreditcardPayment extends Creditcard {
# public static const LABEL:String = "number";
# }
#}
# set the mxml compiler into the path then compile the flex app then,
rake rx:flex:build
Effectively, we think we should use Spree extension to separate
RestfulX stuff.
And we are wondering if it's possible to launch RestfulX generation
directly in the Spree extension folder...
We also need to select only some part of the data model of Spree (we
selected following main classes : Products, Users and Taxonomy).
Then it should be necessary to develop REST services over Spree (in
the same extension or in a 2nd extension).
We are looking to build a special generic RESTful controller (like
Sean's idea).
In fact we take a look on the internal mechanisms of RestfulX. There
is a RxModel class from which derivate all model objects, and this
class provide generic REST service call... (following the Rails
convention :
http://server/controller/action/id.xml)
Following the same pattern, we think the best way is to have a single
controller in Spree which receive request from several routes :
http://server/users/1.xml
http://server/products/new.xml
...
This contoller must be able to determine the good object model from
the current route and return the object XML description using
ActiveRecord.Serialization.to_xml().
More over, this method permit to build complex XML response like
this :
format.xml @order.to_xml(:include=>@user)
to get something like that :
<order>
<order_property1> ... </order_property1>
....
<user>
<user_property1> ... </user_property1>
...
</user>
</order>
Anf finally, we are wondering if it's possible to restrict this super
generic Controller only to desired Models using routes.rb...
This is what we plan to try to develop next week.
You can have a look on RestfulX mailing list too.
http://groups.google.com/group/restfulx-framework/browse_thread/thread/c440c02b654e4c7d
Regards,
Bruno & Pascal.