以本地布局渲染远程视图(Render remote view in local layout)

编程入门 行业动态 更新时间:2024-10-27 23:30:29
以本地布局渲染远程视图(Render remote view in local layout)

我的组织正在考虑将现有的Rails monolith重新实现为Rails服务的集合。 对于内容层,我们的想法是我们的​​API网关将包含整个应用程序的布局信息,并将通过HTTP请求单个视图。 然后,各个服务将呈现其模板,并通过HTTP将其作为呈现的HTML发回。

我的问题是:Rails中是否有一种机制可以通过HTTP请求远程内容,将收到的HTML呈现为ERB / HAML布局模板,然后提供完全呈现的HTML?

My organization is considering re-implementing an existing Rails monolith as a collection of Rails services. For the content layer, our thought was that our API gateway would contain the layout information for the whole app, and would request individual views via HTTP. Individual services would then render their templates and send them back via HTTP as rendered HTML.

My question is this: is there a mechanism in Rails to request remote content via HTTP, to render the received HTML into an ERB/HAML layout template, and then to serve the fully rendered HTML?

最满意答案

就像在控制器中请求该信息然后在ERB模板中将其作为字符串输出一样?

我还缺少一些其他要求吗?

调节器

def index @content = body_of_request_to_service end

视图

... <%= @content %> ...

但是,我不建议使用这种使用Ruby的微服务(除非你有一个了解如何处理异步Ruby IO的开发团队) 。 一个好的经验法则是每个客户端请求只有一个阻止服务请求。

Like requesting that information in a controller and then outputting it as a string in an ERB template?

Is there some other requirement that I'm missing?

Controller

def index @content = body_of_request_to_service end

View

... <%= @content %> ...

But, I wouldn't recommend this style of microservices using Ruby (unless you have a dev-team that understands how to handle async Ruby IO). A good rule of thumb is to only have one blocking service request per client request.

更多推荐

本文发布于:2023-04-29 10:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335992.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   布局   Render   remote   local

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!