语法错误,意外 keyword_else,预期 keyword_end

syntax error, unexpected keyword_else, expecting keyword_end

我正在使用 SLIM,我不确定如何修复缩进。我看到这个错误:

SyntaxError at /users/user syntax error, unexpected keyword_else, expecting keyword_end ; else; ^ /views/users/shared/_user_item.html.slim:18: syntax error, unexpected keyword_ensure, expecting end-of-input

它来自这个文件:

li
  .common_box.box3
    .img_box
        = link_to user do
          - if user.avatar.present?
          img alt="" src="#{user.avatar.try(:image_url, :similar)}" style=("width: 194px;height: 139px;")  /
          - else
            img alt="no image" src="" style=("width: 194px;height: 139px;") /
    .img_detail
      small years
      .circle
        span.age_box = user.age 
      h3 #{user.username} #{current_user.location.state}
      h4 #{user.location.city}, #{user.location.state}
      .green_corner
        img alt="" src="/assets/side_curv.png" /

line 6 上试试这个(你的图片标签没有缩进)。

li
  .common_box.box3
    .img_box
        = link_to user do
          - if user.avatar.present?
            img alt="" src="#{user.avatar.try(:image_url, :similar)}" style=("width: 194px;height: 139px;")  /
          - else
            img alt="no image" src="" style=("width: 194px;height: 139px;") /
    .img_detail
      small years
      .circle
        span.age_box = user.age 
      h3 #{user.username} #{current_user.location.state}
      h4 #{user.location.city}, #{user.location.state}
      .green_corner
        img alt="" src="/assets/side_curv.png" /