Thanks for the suggestions & discussion.
I’m toying with my own philosophy that any GET should be able to be PUT
back.
I store my GET as an XML node tree, the Flex controls modify this, then
I put it back to its original URL. Currently this isn’t efficient as
only one field in one licence may have changed, but there is potential
for non-obtrusive optimisation if the XML nodes can track whether they
or their children have changed.
I got the route by logging all routes to a file with :
def self.dump_routes
result = ‘’
ActionController::Routing::Routes.routes.each { |route| result <<
route.to_s }
end
and then modifying my routes until I got the desired output.
The result is now :
map.resources(:customers,{}) do |customer|
customer.resources(:licences,{})
customer.connect ‘/customers/:customer_id/licences.xml/’, :controller
=> ‘licences’, :action => ‘index’, :format => ‘xml’, :conditions => {
:method => :put }
end
map.resources(:licences,{})
map.connect ‘licences.xml’, :controller => ‘licences’, :action =>
‘index’, :format => ‘xml’, :conditions => { :method => :put }
(and it works) for anyone interested.
I’m using a modified generic rest controller from
Google Code Archive - Long-term storage for Google Code Project Hosting. and the index action
looks like :
def index(options = @options)
if request.method==:get
@page_title ||= 'Listing ’ + resources_display_name
scope_find do
resources_instance_set resource_model.find(:all,
options[:find_options])
end
respond_to do |format|
format.html { render :action => options[:template] || 'index'}
format.xml { render :xml => resources_instance.to_xml }
end
elsif request.method==:put
resourcelist = params[resources_name][resource_name] rescue nil
raise RuntimeError("records not found") unless resourcelist &&
!resourcelist.empty?
resourcelist = [resourcelist] unless resourcelist.is_a? Array
success = true
errors = {}
resourcelist.each do |aResourceHash|
model_instance = resource_model.find_by_id(aResourceHash[‘id’])
success = false unless
model_instance.update_attributes(aResourceHash.filter_include(resource_model.column_names))
errors = model_instance.errors
break if !success
end
if success
render :nothing => true
else
render :xml => errors.to_xml
end
end
end
magpie