Does anyone have recommendations for how I can reduce respond_to blocks? It seems like my JSON formatting takes up a considerable amount of space. The controller, for the most part, responds with HTML but this specific method is called via Ajax and responds in JSON:
def create
# initial setup
respond_to do |format|
unless paid_cash == true || PayPalPayments::OrderValidator.call(order_id)
format.json do
render json: {
status: :unhandled_error,
message: 'Invalid order ID supplied?'
}, status: 400
end
end
if @submitted_application.save(context: :create)
MembershipMailer.with(application: @submitted_application).signup_confirmation.deliver_later
format.json do
render json: {
status: :created,
modal: render_to_string(
partial: 'membership_confirmation_modal.html.erb'
)
}
end
else
format.json do
render json: {
status: :validation_errors,
errors: @submitted_application.errors
}, status: 400
end
end
end
end