lib/ahc_helper.rb in ahc-0.3.2 vs lib/ahc_helper.rb in ahc-0.3.3

- old
+ new

@@ -22,10 +22,22 @@ def respond_with(*resources, &block) controller = params[:controller].split('/').last action = params[:action] @data ||= {} - @data['resources'] = collection + case params[:action] + when 'show' + @data['resource'] = resource + when 'index' + @data['resources'] = resources + when 'create', 'update' + params[:format] = 'json' + if resource.valid? + @data['resource'] = resource + else + @data['errors'] = resource.errors + end + end render_ahc("#{controller}/#{action}") end end