[英]How can I display all the environment variables on an HTML page using Rails?
I have a bunch of environment variables set on my Windows machine that I would like to display on an HTML page. 我在Windows机器上设置了许多环境变量,希望将它们显示在HTML页面上。 I am able to successfully display just one but not sure how to loop and display all of them with key-value pairs. 我仅能成功显示一个,但不确定如何循环使用键值对显示它们。
Please guide. 请指导。
Rails version: 4.2 Rails版本:4.2
Environment Variables: 环境变量:
MY_ENCODING_SCHEME: utf8
DB_CONN_POOL: 10
DB_USER_NAME: guest
DB_PWD: secret
index.html.erb index.html.erb
<div class="table-container">
<table class="table">
<thead>
<tr>
<th colspan="2">Environment Variables</th>
</tr>
</thead>
<tbody>
<tr><td><%= ENV["MY_ENCODING_SCHEME"] %></td></tr>
</tbody>
</table>
You could loop through your environment variables like this 您可以像这样遍历环境变量
<table>
<thead><tr><td>Variable</td><td>Value</td></tr></thead>
<tbody>
<% ENV.each do |k,v| %>
<tr><td><%= k %></td><td><%= v %></td></tr>
<% end %>
</tbody>
</table>
You could always do something like this: 您总是可以这样做:
<% ENV.each do |k, v| %>
<tr>
<td>
<%= "#{k} - #{v}" %>
</td>
</tr>
<% end %>
Is that what you had in mind? 那是你的想法吗?
EDIT: Just be sure this doesn't see the light of day on a production environment! 编辑:请确保在生产环境中看不到这一切!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.