Javascript 调用rails4中js内的配置变量

Javascript 调用rails4中js内的配置变量,javascript,ruby-on-rails,ruby-on-rails-4,Javascript,Ruby On Rails,Ruby On Rails 4,您好,我已经包含了给定的文件config/countries.rb 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", "

您好,我已经包含了给定的文件config/countries.rb

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"] 
现在我想在app/assets/javascripts/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)')
      };
    };
  };
功能检查发货天数(countryValue){
var航运10天14天=[“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”、“KZ”、“LB”、“LC”、“LI”、“LT”、“MQ”、“MU”、“MV”、“NA”、“NU”、“PA”、“PF”、“PY”、“RO”、“SV”、“TD”、“UA”、“UG”、“UZ”、“ZM”]
var装运4天5天=[“AE”、“BD”、“BH”、“IR”、“JO”、“JP”、“KH”、“KW”、“LA”、“LK”、“MM”、“MO”、“NF”、“OM”、“PH”、“PK”、“QA”、“SA”、“IN”、“VN”]
var航运4天7天=[“丹麦”、“澳大利亚”、“西班牙”、“英国”、“美国”]
var航运5天7天=[“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装运3天5天=[“AU”]
var受限国家=[“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”]
如果($.inArray(countryValue,restrictedCountry)>-1){
警报('我们不在这个国家发货')
$('.address next').prop('disabled',true);
}否则{
$('.address next').prop('disabled',false);
如果($.inArray(countryValue,发货10到14)>-1){
$('.shipping days').html('免费配送(平均10-14个工作日)'))
}否则如果($.inArray(countryValue,shipping4to7)>-1){
$('.shipping days').html('免费配送(平均4-7个工作日)'))
}否则如果($.inArray(countryValue,发货4到5)>-1){
$('.shipping days').html('免费配送(平均4-5个工作日)'))
}否则如果($.inArray(countryValue,发货3到5)>-1){
$('.shipping days').html('免费配送(平均3-5个工作日)'))
}否则如果($.inArray(countryValue,发货5到7)>-1){
$('.shipping days').html('免费配送(平均5-7个工作日)'))
}否则{
$('.shipping days').html('免费配送(平均4-7个工作日)'))
};
};
};

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

要将Rails变量传递到js中,请看一看


它可以满足您的需要。

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

var Shipping_10_14_days  = <%= Shipping_10_14_days %>
var装运10天14天=