I created my own responder that always returns my JSON-encoded resource even in PUT / POST.
I put this file in lib/responders/json_responder.rb . Your /lib directory should be automatically loaded.
module Responders::JsonResponder protected # simply render the resource even on POST instead of redirecting for ajax def api_behavior(error) if post? display resource, :status => :created # render resource instead of 204 no content elsif put? display resource, :status => :ok else super end end end
Now, explicitly modify the controller that requires this behavior, or place it in the application controller.
class ApplicationController < ActionController::Base protect_from_forgery responders :json end
Now you should get JSON-encoded resources on PUT.
jpfuentes2 Apr 10 2018-12-12T00: 00Z
source share