implement generic resource#update
authorTom Clegg <tom@clinicalfuture.com>
Fri, 11 Jan 2013 06:25:40 +0000 (22:25 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Fri, 11 Jan 2013 06:25:40 +0000 (22:25 -0800)
app/controllers/application_controller.rb
config/routes.rb

index 8216accfe59b0d14acc345c206290c5b3c99abdb..96c95592ec8286b9fab2252a7bd7b9189937dd43 100644 (file)
@@ -15,7 +15,7 @@ class ApplicationController < ActionController::Base
   def create
     @attrs = params[resource_name]
     if @attrs.nil?
-      raise "no #{resource_name} provided with request #{params.inspect}"
+      raise "no #{resource_name} (or #{resource_name.camelcase(:lower)}) provided with request #{params.inspect}"
     end
     if @attrs.class == String
       @attrs = uncamelcase_hash_keys(JSON.parse @attrs)
@@ -25,6 +25,15 @@ class ApplicationController < ActionController::Base
     show
   end
 
+  def update
+    @attrs = params[resource_name]
+    if @attrs.class == String
+      @attrs = uncamelcase_hash_keys(JSON.parse @attrs)
+    end
+    @object.update_attributes @attrs
+    show
+  end
+
   protected
 
   def model_class
@@ -32,11 +41,14 @@ class ApplicationController < ActionController::Base
   end
 
   def resource_name             # params[] key used by client
-    controller_name.classify.camelcase(:lower)
+    controller_name.singularize
   end
 
   def find_object_by_uuid
     logger.info params.inspect
+    if params[:id] and params[:id].match /\D/
+      params[:uuid] = params.delete :id
+    end
     @object = model_class.where('uuid=?', params[:uuid]).first
   end
 
index ab63db3eae453c47efacf2e81fd82568229b2d13..0c9fe8773928a254f78a7a325fb5fd498c594e90 100644 (file)
@@ -63,6 +63,7 @@ Server::Application.routes.draw do
       resources :nodes
       resources :pipelines
       resources :pipeline_invocations
+      resources :pipelineInvocations
       match '/nodes/:uuid/ping' => 'nodes#ping', :as => :ping_node
       match '/metadata/:target_kind/:target_uuid' => 'metadata#index'
     end