1 class ApplicationController < ActionController::Base
3 before_filter :uncamelcase_params_hash_keys
4 before_filter :find_object_by_uuid, :except => :index
7 @objects ||= model_class.all
16 @attrs = params[resource_name]
18 raise "no #{resource_name} provided with request #{params.inspect}"
20 if @attrs.class == String
21 @attrs = uncamelcase_hash_keys(JSON.parse @attrs)
23 @object = model_class.new @attrs
31 controller_name.classify.constantize
34 def resource_name # params[] key used by client
35 controller_name.classify.camelcase(:lower)
38 def find_object_by_uuid
39 logger.info params.inspect
40 @object = model_class.where('uuid=?', params[:uuid]).first
43 def uncamelcase_params_hash_keys
44 self.params = uncamelcase_hash_keys(params)
47 def uncamelcase_hash_keys(h)
53 elsif k.class == Symbol
54 nk = k.to_s.underscore.to_sym
58 nh[nk] = uncamelcase_hash_keys(v)
67 :kind => "orvos##{resource_name}List",
70 :next_page_token => "",
72 :items => @objects.map { |x| x }
74 render json: @object_list