https://www.aeolusproject.org/redmine/issues/3248
Adds respond_to blocks to create action in ProvidersController
Adds route to POST api/providers => ProvidersController#create
Adds validations_error.xml.haml template
---
src/app/controllers/providers_controller.rb | 19 +++++++++++++++----
src/app/views/api/validation_error.xml.haml | 5 +++++
src/config/routes.rb | 2 +-
3 files changed, 21 insertions(+), 5 deletions(-)
create mode 100644 src/app/views/api/validation_error.xml.haml
diff --git a/src/app/controllers/providers_controller.rb
b/src/app/controllers/providers_controller.rb
index 7b159bd..f258316 100644
--- a/src/app/controllers/providers_controller.rb
+++ b/src/app/controllers/providers_controller.rb
@@ -105,13 +105,24 @@ class ProvidersController < ApplicationController
params[:provider][:provider_type_id] = provider_type.id
end
@provider = Provider.new(params[:provider])
+
if @provider.save
@provider.assign_owner_roles(current_user)
- flash[:notice] = t"providers.flash.notice.added"
- redirect_to edit_provider_path(@provider)
+ respond_to do |format|
+ format.html do
+ flash[:notice] = t"providers.flash.notice.added"
+ redirect_to edit_provider_path(@provider)
+ end
+ format.xml { render :partial => 'detail', :locals => { :provider
=> @provider } }
+ end
else
- flash[:warning] = t"providers.flash.error.not_added"
- render :action => "new"
+ respond_to do |format|
+ format.html do
+ flash[:warning] = t"providers.flash.error.not_added"
+ render :action => "new"
+ end
+ format.xml { render :template => 'api/validation_error', :locals =>
{ :errors => @provider.errors }, :status => :bad_request }
+ end
end
end
diff --git a/src/app/views/api/validation_error.xml.haml
b/src/app/views/api/validation_error.xml.haml
new file mode 100644
index 0000000..f9f17f2
--- /dev/null
+++ b/src/app/views/api/validation_error.xml.haml
@@ -0,0 +1,5 @@
+!!!XML
+%errors
+ - errors.full_messages.each do |message_error|
+ %error
+ %message= message_error
diff --git a/src/config/routes.rb b/src/config/routes.rb
index a95389f..21e73ed 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -258,7 +258,7 @@ Conductor::Application.routes.draw do
end
scope "/api" do
- resources :providers, :as => 'api_providers', :only => [:index, :show]
+ resources :providers, :as => 'api_providers', :only => [:index, :show,
:create]
resources :provider_accounts, :as => 'api_provider_accounts', :only =>
[:index, :show]
resources :provider_types, :as => 'api_provider_types', :only =>
[:index, :show]
end
--
1.7.7.6