从控制器获取视图路径#action
我需要编译(通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这应该是等效的:
相关文档:
AbstractController::Rendering#view_renderer
ActionView::Renderer#render
ActionView::TemplateRenderer
I think this ought to be equivalent:
Related docs:
AbstractController::Rendering#view_renderer
ActionView::Renderer#render
ActionView::TemplateRenderer