在其他控制器API中使用Repost-ruby-gems调用Create Action获取模板未找到错误



我在Ruby on rails应用程序上有两个控制器API,A和B。如果参数通过了控制器A中的验证,它将重定向到控制器B上的create操作。如果没有,则继续在控制器A上运行逻辑。

起初,我尝试使用redirect_to,但由于操作是使用POST方法,所以它不起作用。然后我尝试使用repost红宝石宝石https://rubygems.org/gems/repost.我遵循了文档,但当我测试API时,它返回No template found for xxxController#create, rendering head :no_content。由于它是一个API,我认为它不需要查看。

我曾尝试为该控制器添加视图,但它最终将html呈现为响应。有人想让它重定向到其他控制器吗?或者使用其他宝石来解决这个问题的其他方法?

编辑我也尝试以这种方式呈现html:

render html: Repost::Senpai.perform('http://xxx', params: { auth: request.params[:user] }, options: {authenticity_token: :auto, autosubmit: true}).html_safe, status: status

我把gem回购的逻辑复制到https://github.com/vergilet/repost/blob/master/lib/repost/extend_controller.rb.但是,html仍然只是对响应进行了渲染。它不会重定向到给定的url

repost工作的机制是呈现HTML表单并自动提交。仅调用Repost::Senpai.perform不会呈现HTML。

您可以尝试以下操作。它基于转发对ActionController的扩展::Base

render html: Repost::Senpai.perform(
'http://xxxx',
params: { auth: request.params[:user] },
).html_safe, status: :ok