简体   繁体   中英

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.

Or all equivalent data into a view.

Is it feasible?

rake about is merely outputting the value of Rails::Info.to_s to stdout. You can thus use this data directly from Rails without invoking rake (neither inline nor via a shellout):

<%= Rails::Info.to_s %>

Since the data is intended for display in a text console, it is not directly suitable for HTML output. You can make it more readable by requesting HTML output with

<%= 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>
  <%= 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.properties

You can use Backticks to execute system command. So inside view it would look like:

<%= `rake about` %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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