我需要渲染从 API 收到的 html 代码。
在 Rails 6 中:我在控制器中执行此操作,并且运行良好。我调用了收到响应的 web 服务,然后我被重定向到渲染生成的代码。美好的 !
class GatewayController < ApplicationController
def new
init_gateway_call
end
def create
call_gateway
render_gateway_response
end
private
...
def render_gateway_response
render(html: @gateway_response.message.html_safe)
end
end
新的.html.erb:
<%= form_with url: gateway_path, local: true do |f| %>
...
<% end %>
没有:create.html.erb
** 导轨 7 **
我打电话给网络服务。我得到了答案,但我的页面空闲,我收到了这个错误。
Error: Form responses must redirect to another location at FormSubmission.requestSucceededWithResponse (application-0f0c10fb8f5683e32fc53a93a8a323c328de61682ca16fb65a6a2b8a3ba5d087.js:1614) at FetchRequest.receive (application-0f0c10fb8f5683e32fc53a93a8a323c328de61682ca16fb65a6a2b8a3ba5d087.js:1390) at FetchRequest.perform (application-0f0c10fb8f5683e32fc53a93a8a323c328de61682ca16fb65a6a2b8a3ba5d087.js:1374)
到目前为止,我尝试过:
# GatewayController
respond_to :create, format: :html, gateway_response: @gateway_response.message.html_safe
<%= gateway_response %>
没有成功......你有什么想法吗?不然会是个长周末^^