从控制器获取视图路径#action

发布于 2025-01-04 20:35:11 字数 539 浏览 0 评论 0原文

我需要编译(通过 HAML)并获取视图文件的内容。现在我正在控制器的操作中执行此操作:

path     = File.join(views_path, 'recommend/email_texts/video_uploaded.html.haml'))
contents = File.open(path) { |f| f.read }
message  = Haml::Engine.new(file).render(self)

# file is being rendered in a context of self because it includes some action
# specific vars, as well as calls to params method of controller

然后我需要将消息发送到 SOAP 端点并向浏览器呈现“操作成功”页面。 只是说

所以问题是 – 有没有合适的方法可以替换上面的 3 行?如果这里没有太多需要重构的地方——是否有任何好的实践来完成我正在处理的任务?

先感谢您!

I need to compile (via HAML) and get the contents of the view file. Right now I'm doing this inside an action of the controller:

path     = File.join(views_path, 'recommend/email_texts/video_uploaded.html.haml'))
contents = File.open(path) { |f| f.read }
message  = Haml::Engine.new(file).render(self)

# file is being rendered in a context of self because it includes some action
# specific vars, as well as calls to params method of controller

Then I need to send the message to the SOAP endpoint and render a "Operation successful" page to the browser. Just saying

So the question is – is there a suitable approach I can replace the 3 lines above with? If there's not much to refactor here – is there any good practice to accomplish tasks of a kind I am working on?

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离不开的别离 2025-01-11 20:35:11

我认为这应该是等效的:

message = view_renderer.render self,
            :template => 'recommend/email_texts/video_uploaded'

相关文档:

I think this ought to be equivalent:

message = view_renderer.render self,
            :template => 'recommend/email_texts/video_uploaded'

Related docs:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文