Rails 3:如何内联渲染文本文件?
全部。
这里有 Rails n00b...
我正在编写一个报告事务状态的应用程序。 渲染的 HTML 中的一些内容来自实例变量 在控制器中初始化,其他内容来自文本文件 (例如,日志文件)我想使用
标签在 HTML 中呈现。
做到这一点的“Rails Way”是什么?
谢谢您的宝贵时间...
All.
A Rails n00b here...
I'm writing an application that reports the status of a transaction.
Some of the content in the rendered HTML comes from instance variables
initialized in the controller, while other content comes from text files
(e.g., log files) that I want to render in the HTML using <pre>
tags.
What is the "Rails Way" to do this?
Thank you for your time...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这里:http://edgeguides.rubyonrails.org/layouts_and_rendering.html
Here you go: http://edgeguides.rubyonrails.org/layouts_and_rendering.html
在某些情况下(当文件不小且加载有延迟时),我更喜欢加载页面内容,然后使用 jQuery ajax 请求加载文件内容。
例如,假设我有一个具有文件路径属性的模型。在
view
布局中,我正在做这样的事情:然后在相应的
js
文件中,我将像这样加载上下文:当然,您可以检查 jQuery ajax 文档了解更多选项。例如,您可以像这样使用
loading
渲染pre
标签:或者也使用其他
jQuery
动画。In some cases (when the file is not small and loading it is connected with a delay), I prefer to load the page content and then to use
jQuery
ajax request to load the file content.For example, let's say I have a model with file path attribute. In the
view
layout I am doing something like this:Then in the corresponding
js
file I am loading the context like this:Of course you can check the jQuery ajax documentation for more options. For example, you can render the
pre
tag withloading
like this:or use other
jQuery
animations as well.