在我的网络应用中,当我检查Heroku上的结算页面的HTML时 - 表单的hide()
属性为空,但在我的本地计算机上(在开发和生产模式下)它正确指向到ENV ['TWOCHECKOUT_PURCHASE_URL']变量的值。
表单的action
属性必须包含不同的URL,具体取决于Rails正在运行的环境。如何使它工作?
application.yml
action
home.html.erb
TWOCHECKOUT_PURCHASE_URL: 'https://sandbox.2checkout.com/checkout/purchase'
sbBillingDirective.js.erb
<sb-billing></sb-billing>
billing_directive.html.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
}
答案 0 :(得分:2)
在这里找到了答案: Access Rails env variable from Angular Controller
我添加.html_safe
之后就可以了:
<form id="2checkout"
action="<%= ENV['TWOCHECKOUT_PURCHASE_URL'].html_safe %>"
method="post">
</form>