如何将 ENV 变量的值注入 Angular 模板?

How to inject value of ENV variable into Angular template?

在我的网络应用程序中,当我检查 Heroku 上的结算页面 HTML - 表单的 action 属性 为空 ,但在我的本地计算机上(在开发和生产模式)它正确地指向 ENV['TWOCHECKOUT_PURCHASE_URL'] 变量的值。

表单的 action 属性必须包含不同的 URL,具体取决于环境 Rails 是 运行。如何让它发挥作用?

application.yml

TWOCHECKOUT_PURCHASE_URL: 'https://sandbox.2checkout.com/checkout/purchase'

home.html.erb

<sb-billing></sb-billing>

sbBillingDirective.js.erb

//= depend_on_asset "billing_directive.html"

(function() {

    angular
        .module('scrumban.widgets')
        .directive('sbBilling', billingDirective);

    function billingDirective() {
        return {
            restrict: 'EA',
            scope: {},
            replace: true,
            templateUrl: '<%= asset_path("billing_directive.html") %>',
            controller: BillingController,
            controllerAs: 'vm'
        }
    }

    BillingController.$inject = ['$scope', 'BillingService', '_'];
    function BillingController($scope, BillingService, _) {
      // not relevant code
    }

billing_directive.html.erb

<form id="2checkout" 
      action="<%= ENV['TWOCHECKOUT_PURCHASE_URL'] %>"
      method="post">
</form>

在这里找到答案:

在我添加 .html_safe 之后它起作用了:

<form id="2checkout" 
      action="<%= ENV['TWOCHECKOUT_PURCHASE_URL'].html_safe %>"
      method="post">
</form>