ActiveSupport的ng-options :: TimeZone返回意外的表达式结尾:[

时间:2017-11-28 16:44:53

标签: ruby-on-rails angularjs erb ng-options

我试图在erb文件中列出时区选项。我有以下代码:

<select class="pull-left" ng-model="schedule.deliver_timezone"
                          ng-options="zone for zone in <%= ActiveSupport::TimeZone.zones_map.map { |zone_name, zone_desc| zone_name.to_s } %>" 
                          name="deliver_at_tz"/>

如果我只是运行ActiveSupport::TimeZone.zones_map.map { |zone_name, zone_desc| zone_name.to_s },我会按预期获得一系列时区名称。但是,当实际点击此模板时,我得到:

  

意外的表达结束:[

这会将以下混乱信息转储到控制台中:

<select class="pull-left ng-pristine ng-valid" ng-model="schedule.deliver_timezone" ng-options="zone for zone in [" utc",="" "eastern="" time="" (us="" &="" canada)",="" "international="" date="" line="" west",="" "midway="" island",="" "american="" samoa",="" "hawaii",="" "alaska",="" "pacific="" "tijuana",="" "mountain="" "arizona",="" "chihuahua",="" "mazatlan",="" "central="" "saskatchewan",="" "guadalajara",="" "mexico="" city",="" "monterrey",="" america",="" "indiana="" (east)",="" "bogota",="" "lima",="" "quito",="" "atlantic="" (canada)",="" "caracas",="" "la="" paz",="" "santiago",="" "newfoundland",="" "brasilia",="" "buenos="" aires",="" "georgetown",="" "greenland",="" "mid-atlantic",="" "azores",="" "cape="" verde="" is.",="" "dublin",="" "edinburgh",="" "lisbon",="" "london",="" "casablanca",="" "monrovia",="" "belgrade",="" "bratislava",="" "budapest",="" "ljubljana",="" "prague",="" "sarajevo",="" "skopje",="" "warsaw",="" "zagreb",="" "brussels",="" "copenhagen",="" "madrid",="" "paris",="" "amsterdam",="" "berlin",="" "bern",="" "rome",="" "stockholm",="" "vienna",="" "west="" central="" africa",="" "bucharest",="" "cairo",="" "helsinki",="" "kyiv",="" "riga",="" "sofia",="" "tallinn",="" "vilnius",="" "athens",="" "istanbul",="" "minsk",="" "jerusalem",="" "harare",="" "pretoria",="" "moscow",="" "st.="" petersburg",="" "volgograd",="" "kuwait",="" "riyadh",="" "nairobi",="" "baghdad",="" "tehran",="" "abu="" dhabi",="" "muscat",="" "baku",="" "tbilisi",="" "yerevan",="" "kabul",="" "ekaterinburg",="" "islamabad",="" "karachi",="" "tashkent",="" "chennai",="" "kolkata",="" "mumbai",="" "new="" delhi",="" "kathmandu",="" "astana",="" "dhaka",="" "sri="" jayawardenepura",="" "almaty",="" "novosibirsk",="" "rangoon",="" "bangkok",="" "hanoi",="" "jakarta",="" "krasnoyarsk",="" "beijing",="" "chongqing",="" "hong="" kong",="" "urumqi",="" "kuala="" lumpur",="" "singapore",="" "taipei",="" "perth",="" "irkutsk",="" "ulaan="" bataar",="" "seoul",="" "osaka",="" "sapporo",="" "tokyo",="" "yakutsk",="" "darwin",="" "adelaide",="" "canberra",="" "melbourne",="" "sydney",="" "brisbane",="" "hobart",="" "vladivostok",="" "guam",="" "port="" moresby",="" "magadan",="" "solomon="" caledonia",="" "fiji",="" "kamchatka",="" "marshall="" "auckland",="" "wellington",="" "nuku'alofa",="" "tokelau="" "samoa"]"="" name="deliver_at_tz">

我不确定这种格式究竟应该如何看,但它显然是错误的。这个逻辑究竟出了什么问题?

完整跟踪(对敏感信息进行了复制):

Error: [$parse:ueoe] Unexpected end of expression: [
http://errors.angularjs.org/1.3.0-beta.10/$parse/ueoe?p0=%5B
    at http://127.0.0.1:3000/application.js <select class="pull-left ng-pristine ng-valid" ng-model="schedule.deliver_timezone" ng-options="zone for zone in [" utc",="" "eastern="" time="" (us="" &="" canada)",="" "international="" date="" line="" west",="" "midway="" island",="" "american="" samoa",="" "hawaii",="" "alaska",="" "pacific="" "tijuana",="" "mountain="" "arizona",="" "chihuahua",="" "mazatlan",="" "central="" "saskatchewan",="" "guadalajara",="" "mexico="" city",="" "monterrey",="" america",="" "indiana="" (east)",="" "bogota",="" "lima",="" "quito",="" "atlantic="" (canada)",="" "caracas",="" "la="" paz",="" "santiago",="" "newfoundland",="" "brasilia",="" "buenos="" aires",="" "georgetown",="" "greenland",="" "mid-atlantic",="" "azores",="" "cape="" verde="" is.",="" "dublin",="" "edinburgh",="" "lisbon",="" "london",="" "casablanca",="" "monrovia",="" "belgrade",="" "bratislava",="" "budapest",="" "ljubljana",="" "prague",="" "sarajevo",="" "skopje",="" "warsaw",="" "zagreb",="" "brussels",="" "copenhagen",="" "madrid",="" "paris",="" "amsterdam",="" "berlin",="" "bern",="" "rome",="" "stockholm",="" "vienna",="" "west="" central="" africa",="" "bucharest",="" "cairo",="" "helsinki",="" "kyiv",="" "riga",="" "sofia",="" "tallinn",="" "vilnius",="" "athens",="" "istanbul",="" "minsk",="" "jerusalem",="" "harare",="" "pretoria",="" "moscow",="" "st.="" petersburg",="" "volgograd",="" "kuwait",="" "riyadh",="" "nairobi",="" "baghdad",="" "tehran",="" "abu="" dhabi",="" "muscat",="" "baku",="" "tbilisi",="" "yerevan",="" "kabul",="" "ekaterinburg",="" "islamabad",="" "karachi",="" "tashkent",="" "chennai",="" "kolkata",="" "mumbai",="" "new="" delhi",="" "kathmandu",="" "astana",="" "dhaka",="" "sri="" jayawardenepura",="" "almaty",="" "novosibirsk",="" "rangoon",="" "bangkok",="" "hanoi",="" "jakarta",="" "krasnoyarsk",="" "beijing",="" "chongqing",="" "hong="" kong",="" "urumqi",="" "kuala="" lumpur",="" "singapore",="" "taipei",="" "perth",="" "irkutsk",="" "ulaan="" bataar",="" "seoul",="" "osaka",="" "sapporo",="" "tokyo",="" "yakutsk",="" "darwin",="" "adelaide",="" "canberra",="" "melbourne",="" "sydney",="" "brisbane",="" "hobart",="" "vladivostok",="" "guam",="" "port="" moresby",="" "magadan",="" "solomon="" caledonia",="" "fiji",="" "kamchatka",="" "marshall="" "auckland",="" "wellington",="" "nuku'alofa",="" "tokelau="" "samoa"]"="" name="deliver_at_tz">

1 个答案:

答案 0 :(得分:0)

尝试这样做,应该有效

<select class="pull-left" 
        ng-model="schedule.deliver_timezone"
        ng-options='zone for zone in <%= "[\"#{ActiveSupport::TimeZone.zones_map.values.collect{|z| z.name }.join('","')}\"]" %>' 
        name="deliver_at_tz" />