2016-09-22 38 views
2

你好,我已经包括给定文件的config/countries.rb配置变量rails4

Shipping_10_14_days = ["AD", "AF", "AL", "AM", "AS", "AW", "AZ", "BA", "BB", "BM", "BS", "BZ", "CM", "CU", "CV", "DM", "DZ", "EE", "FK", "FM", "FO", "GF", "GL", "GY", "IS", "JM", "KG", "KY", "KZ", "LB", "LC", "LI", "LT", "MQ", "MU", "MV", "NA", "NU", "PA", "PF", "PY", "RO", "SV", "TD", "UA", "UG", "UZ", "ZM"] 
Shipping_4_5_days = ["AE", "BD", "BH", "IR", "JO", "JP", "KH", "KW", "LA", "LK", "MM", "MO", "NF", "OM", "PH", "PK", "QA", "SA", "IN", "VN"] 
Shipping_4_7_days = ["DK", "AT", "VI", "GB", "US"] 
Shipping_5_7_days = ["BA", "BE", "BG", "CH", "CR", "CY", "CZ", "DE", "EG", "ES", "FI", "FR", "GE", "GH", "GL", "GR", "HN", "HR", "HU", "IE", "IL", "IT", "LU", "LV", "MA", "MC", "MN", "MT", "NA", "NC", "NG", "NL", "NO", "PL", "PT", "SE", "SK", "TR", "TW", "TZ", "ZA", "SG"] 
Shipping_3_5_days = ["AU"] 
Restricted_Country = ["AR", "BN", "BR", "BS", "CL", "CN", "CO", "CR", "EC", "FK", "GP", "GT", "GU", "ID", "IS", "MP", "MX", "NZ", "PE", "PM", "RS", "RU", "TH", "TT", "UY"] 

现在我想打电话给我的应用程序/资产/ Java脚本/ test.js内这些变量 请指引我如何调用这些变量

function checkShippingDays(countryValue) { 
    var Shipping_10_14_days = ["AD", "AF", "AL", "AM", "AS", "AW", "AZ", "BA", "BB", "BM", "BS", "BZ", "CM", "CU", "CV", "DM", "DZ", "EE", "FK", "FM", "FO", "GF", "GL", "GY", "IS", "JM", "KG", "KY", "KZ", "LB", "LC", "LI", "LT", "MQ", "MU", "MV", "NA", "NU", "PA", "PF", "PY", "RO", "SV", "TD", "UA", "UG", "UZ", "ZM"] 
    var Shipping_4_5_days = ["AE", "BD", "BH", "IR", "JO", "JP", "KH", "KW", "LA", "LK", "MM", "MO", "NF", "OM", "PH", "PK", "QA", "SA", "IN", "VN"] 
    var Shipping_4_7_days = ["DK", "AT", "VI", "GB", "US"] 
    var Shipping_5_7_days = ["BA", "BE", "BG", "CH", "CR", "CY", "CZ", "DE", "EG", "ES", "FI", "FR", "GE", "GH", "GL", "GR", "HN", "HR", "HU", "IE", "IL", "IT", "LU", "LV", "MA", "MC", "MN", "MT", "NA", "NC", "NG", "NL", "NO", "PL", "PT", "SE", "SK", "TR", "TW", "TZ", "ZA", "SG"] 
    var Shipping_3_5_days = ["AU"] 
    var Restricted_Country = ["AR", "BN", "BR", "BS", "CL", "CN", "CO", "CR", "EC", "FK", "GP", "GT", "GU", "ID", "IS", "MP", "MX", "NZ", "PE", "PM", "RS", "RU", "TH", "TT", "UY"] 

    if ($.inArray(countryValue, restrictedCountry) > -1) { 
     alert('we don not ship in this country') 
     $('.adress-next').prop('disabled', true); 
    } else{ 
     $('.adress-next').prop('disabled', false); 
     if ($.inArray(countryValue, shipping10to14) > -1) { 
     $('.shipping-days').html('<strong>FREE</strong> Delivery (average 10-14 business days)') 
     } else if ($.inArray(countryValue, shipping4to7) > -1) { 
     $('.shipping-days').html('<strong>FREE</strong> Delivery (average 4-7 business days)') 
     } else if ($.inArray(countryValue, shipping4to5) > -1) { 
     $('.shipping-days').html('<strong>FREE</strong> Delivery (average 4-5 business days)') 
     } else if ($.inArray(countryValue, shipping3to5) > -1) { 
     $('.shipping-days').html('<strong>FREE</strong> Delivery (average 3-5 business days)') 
     } else if ($.inArray(countryValue, shipping5to7) > -1) { 
     $('.shipping-days').html('<strong>FREE</strong> Delivery (average 5-7 business days)') 
     } else { 
     $('.shipping-days').html('<strong>FREE</strong> Delivery (average 4-7 business days)') 
     }; 
    }; 
    }; 

我需要在js文件中调用这些变量。

回答

2

创建test.js.erb文件,并使用

var Shipping_10_14_days = <%= Shipping_10_14_days %>