简体   繁体   English

如何使用Rails在HTML页面上显示所有环境变量?

[英]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.

相关问题 如何在Rails中将环境变量显示为一组 - How to display environment variables as a group in Rails 如何在.html.erb页面上显示控制器的变量(循环中)? 红宝石在铁轨上 - how can I display controller's variable (which is on a loop) on .html.erb page? ruby on rails 在Rails中,如何在HTML页面上将javascript显示为文本? - In Rails how do I display javascript as text on an HTML page? 如何在我正在查看的页面上显示项目数? (在rails / shopify上使用液体/红宝石) - How I can display the number of items on the page I am looking at? (using liquid / ruby on rails / shopify) 如何通过Rspec使用Guard更改环境变量 - How can I change environment variables using guard with Rspec 使用Rails 3在同一页面上显示所有数据 - Display all the data in the same page using Rails 3 Rails:如何在某个状态代码上显示页面? - Rails: How can I display a page on a certain status code? 如何使Rails识别config / environment_variables.yml中定义的环境变量? - How do I get Rails to recognize environment variables defined in config/environment_variables.yml? 可以使用HTML代码识别环境吗? - Can I Identify The Environment Using HTML Code? Rails3:如何根据环境设置应用程序变量 - Rails3: How do I set variables for the app depending on the ENVIRONMENT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM