【问题标题】:Embedded ruby syntax issue嵌入式 ruby​​ 语法问题
【发布时间】:2020-01-03 23:15:44
【问题描述】:

我在让这个嵌入式 Ruby 工作时遇到问题:

<%= image_tag "svg/illustrations/non-standard-hero-shape.svg", class: "js-svg-injector", data: {
   img_paths: '[
                {"targetId": "#SVGNonStandardHeroShapeImg1", "newPath": "<%= image_path(\'cover-photo.jpg\') %>"},
                {"targetId": "#SVGNonStandardHeroShapeImg2", "newPath": "<%= image_path(\'cover-photo.jpg\') %>"}
               ]',
   parent: "#SVGNonStandardHeroShape" } %>

两次调用都有问题

<%= image_path(\'cover-photo.jpg\') %>

错误是:

syntax error, unexpected tIDENTIFIER, expecting '}'   
syntax error, unexpected ']', expecting ')'   

【问题讨论】:

    标签: ruby embedded-ruby


    【解决方案1】:

    我强烈建议将此数据构建为纯 ruby​​ 对象,然后将其编码为 JSON。那你就不用担心那么多&lt;%=标签了。

    img_paths: [
      {
        targetId: "#SVGNonStandardHeroShapeImg1",
        newPath: image_path('cover-photo.jpg')
      },
      {
        targetId: "#SVGNonStandardHeroShapeImg2",
        newPath: image_path('cover-photo.jpg')
      },
    ].to_json
    

    【讨论】:

      猜你喜欢
      • 2018-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-11
      • 2015-08-02
      相关资源
      最近更新 更多