简体   繁体   English

Ruby-on-Rails:如何在 Rails 视图中显示所有“rake:about”数据?

[英]Ruby-on-Rails : how to display all “rake:about” data inside a Rails view?

I would like to display the output of "rake:about" inside a Rails view.我想在 Rails 视图中显示“rake:about”的 output。

Or all equivalent data into a view.或将所有等效数据放入视图中。

Is it feasible?可行吗?

rake about is merely outputting the value of Rails::Info.to_s to stdout. rake about只是将Rails::Info.to_s的值输出到标准输出。 You can thus use this data directly from Rails without invoking rake (neither inline nor via a shellout):因此,您可以直接从 Rails 中使用这些数据,而无需调用rake (既不是内联也不是通过 shellout):

<%= Rails::Info.to_s %>

Since the data is intended for display in a text console, it is not directly suitable for HTML output.由于数据旨在显示在文本控制台中,因此它不直接适用于 HTML output。 You can make it more readable by requesting HTML output with您可以通过请求 HTML output 使其更具可读性

<%= raw Rails::Info.to_html %>

or by just wrapping the whole block in <pre> tags so that it is shown similar to how it would look on the console:或者只是将整个块包装在<pre>标记中,以便它的显示类似于它在控制台上的外观:

<pre>
  <%= Rails::Info.to_s %>
</pre>

Finally, if you want to format the details yourself, you can get the raw properties shown by Rails::Info as an array of arrays with最后,如果你想自己格式化细节,你可以得到Rails::Info显示的原始属性作为 arrays 的数组

Rails::Info.properties

You can use Backticks to execute system command.您可以使用反引号来执行系统命令。 So inside view it would look like:所以在内部视图中它看起来像:

<%= `rake about` %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM