javascript - 部署 Ruby On Rails 项目时出现意外的 INDENT

标签 javascript ruby-on-rails ruby syntax-error indentation

当我第一次部署到新服务器时,我收到此错误。我已经包含了它引用的文件。以及部署过程中显示的错误。

如有任何帮助,我们将不胜感激。

    servers: ["108.235.52.160"]
    [108.235.52.160] executing command
 ** [out :: 108.235.52.160] rake aborted!
 ** [out :: 108.235.52.160] SyntaxError: unexpected INDENT
 ** [out :: 108.235.52.160] (in /home/deployer/loadmax/releases/20140328165152/a
pp/assets/javascripts/subscriptions.js.coffee)
 ** [out :: 108.235.52.160]
 ** [out :: 108.235.52.160] Tasks: TOP => assets:precompile:primary

文件:

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$(document).ready ->
  if window.location.search.substring(1) == "demo=true"
    $("select#sub").val("6")
    $(".price").hide()
  $('#package').change ->
    if $('#package option:selected').val() == "4" or $('#package option:selected').val() == "6"
      $(".price option[value='299']").remove()
      $(".price option[value='59.99']").remove()
    else
      $(".price").append("<option value='299'>299 Annually</option>")
      $(".price").append("<option value='59.99'>59.99 Monthly</option>")
  $('.recurrence').change ->
    if $('.recurrence option:selected').val() == 'Annual'
      $(".price").append("<option value='299'>299</option>")
      $(".price").append("<option value='239'>239</option>")
      $(".price").append("<option value='199'>199</option>")
      $(".price option[value='39.99']").remove()
    else
      $(".price").append("<option value='39.99'>39.99</option>")
      $(".price option[value='299']").remove()
      $(".price option[value='239']").remove()
      $(".price option[value='199']").remove()
  $('#subscription_tier').change ->
    if $('#subscription_tier option:selected').val() == '4'
      $("label[for='recurrence_recurrence']").hide()
      $(".recurrence").hide()
      $("label[for='price_point_Price point']").hide()
      $(".price").hide()
    else
      $("label[for='recurrence_recurrence']").show()
      $(".recurrence").show()
      $("label[for='price_point_Price point']").show()
      $(".price").show()
  $('#sub').change ->
    if $('#sub option:selected').val() == "6"
      $(".price").hide()
      $(".recurrence").hide()
    else
      $(".price").show()
      $(".recurrence").show()
  $('.email').change ->
    email = $(this).val()
    $.get "/users/?email="+email, (user) ->
      if user.length == 0
        $('#alert_placeholder').hide()
        $('.submit').show()
      else
        error_message = "This email address is already in use."
        $('#alert_placeholder').show()
        $('#alert_placeholder').
        html("<div class='alert alert-error alert-block'><h4 class='alert-heading'>Duplicate Email!</h4><span>#{error_message}</span></div>")
        $('.submit').hide()
   $('.name').change ->
      name = $(this).val() ->
    name = name.replaceAll("[^A-Za-z0-9]", "");
        if $(this).name.val() ->
          $('#alert_placeholder').hide()
          $('.submit').show()
      else
        error_message = "No comma's allowed in form."
        $('#alert_placeholder').show()
        $('#alert_placeholder').
        html("<div class='alert alert-error alert-block'><h4 class='alert-heading'>Comma Error!</h4><span>#{error_message}</span></div>")
        $('.submit').hide()
  $('.mc').change ->
    mc = $(this).val()
    unless mc==''
      $.get "/companies/?mc="+mc, (companies) ->
        unless companies.length == 0
          for company in companies
            if company['status'] == true
              #if there is an active company with this mc number, then we throw
              #an error instructing the Sales Agent to refer the customer to an
              #Account Manager.
              error_message="This company has an active account in loadmax. Please refer the customer to an Account Manager"
              $('#alert_placeholder').
              html("<div class='alert alert-error alert-block'><h4 class='alert-heading'>Active Company Error!</h4><span>#{error_message}</span></div>")
              active_company_exists = true
          unless active_company_exists
            popover_text = 'There exist inactive account(s) in our system with the
            same MC number:<table class="table table-striped">'
            li = []
            for company in companies
              #If we've reached here, then there exists an inactive account with
              #the same MC number. The get request bellow will always return
              #one company, as should be obvious.
              temp = ''
              $.ajax
                url: "/subscriptions?company_id=#{company['id']}"
                type: "GET"
                async: false
                success: (subscription) ->
                  href = "http://secure.loadmax.com/subscriptions/dashboard/"+
                  subscription[0]['id']+"?paysysid="+subscription[0]['paysysid']
                  temp += '<tr><td><b>'+company['name']+'</b><td>'
                  temp += "<td><a href="+href+"> Use </a></td></tr>"
              .done ->
                li.push temp
            popover_text += li.join " "
            popover_text += "</table>"
            $('.mc-popover').popover(html: true, placement: 'right', content: popover_text )
            $('.mc-popover').popover("show")
        else

Coffeescript 网站帮助了很多人,谢谢大家..

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$(document).ready ->
  if window.location.search.substring(1) == "demo=true"
    $("select#sub").val("6")
    $(".price").hide()
  $('#package').change ->
    if $('#package option:selected').val() == "4" or $('#package option:selected').val() == "6"
      $(".price option[value='299']").remove()
      $(".price option[value='59.99']").remove()
    else
      $(".price").append("<option value='299'>299 Annually</option>")
      $(".price").append("<option value='59.99'>59.99 Monthly</option>")
  $('.recurrence').change ->
    if $('.recurrence option:selected').val() == 'Annual'
      $(".price").append("<option value='299'>299</option>")
      $(".price").append("<option value='239'>239</option>")
      $(".price").append("<option value='199'>199</option>")
      $(".price option[value='39.99']").remove()
    else
      $(".price").append("<option value='39.99'>39.99</option>")
      $(".price option[value='299']").remove()
      $(".price option[value='239']").remove()
      $(".price option[value='199']").remove()
  $('#subscription_tier').change ->
    if $('#subscription_tier option:selected').val() == '4'
      $("label[for='recurrence_recurrence']").hide()
      $(".recurrence").hide()
      $("label[for='price_point_Price point']").hide()
      $(".price").hide()
    else
      $("label[for='recurrence_recurrence']").show()
      $(".recurrence").show()
      $("label[for='price_point_Price point']").show()
      $(".price").show()
  $('#sub').change ->
    if $('#sub option:selected').val() == "6"
      $(".price").hide()
      $(".recurrence").hide()
    else
      $(".price").show()
      $(".recurrence").show()
  $('.email').change ->
    email = $(this).val()
    $.get "/users/?email="+email, (user) ->
      if user.length == 0
        $('#alert_placeholder').hide()
        $('.submit').show()
      else
        error_message = "This email address is already in use."
        $('#alert_placeholder').show()
        $('#alert_placeholder').
        html("<div class='alert alert-error alert-block'><h4 class='alert-heading'>Duplicate Email!</h4><span>#{error_message}</span></div>")
        $('.submit').hide()
   $('.name').change ->
      name = $(this).val() ->
        name = name.replaceAll("[^A-Za-z0-9]", "");
        if $(this).name.val()
          $('#alert_placeholder').hide()
          $('.submit').show()
        else
          error_message = "No comma's allowed in form."
          $('#alert_placeholder').show()
          $('#alert_placeholder').
          html("<div class='alert alert-error alert-block'><h4 class='alert-heading'>Comma Error!</h4><span>#{error_message}</span></div>")
          $('.submit').hide()
  $('.mc').change ->
    mc = $(this).val()
    unless mc==''
      $.get "/companies/?mc="+mc, (companies) ->
        unless companies.length == 0
          for company in companies
            if company['status'] == true
              #if there is an active company with this mc number, then we throw
              #an error instructing the Sales Agent to refer the customer to an
              #Account Manager.
              error_message="This company has an active account in loadmax. Please refer the customer to an Account Manager"
              $('#alert_placeholder').
              html("<div class='alert alert-error alert-block'><h4 class='alert-heading'>Active Company Error!</h4><span>#{error_message}</span></div>")
              active_company_exists = true
            unless active_company_exists
              popover_text = 'There exist inactive account(s) in our system with the
              same MC number:<table class="table table-striped">'
              li = []
              for company in companies
                #If we've reached here, then there exists an inactive account with
                #the same MC number. The get request bellow will always return
                #one company, as should be obvious.
                temp = ''
                $.ajax
                  url: "/subscriptions?company_id=#{company['id']}"
                  type: "GET"
                  async: false
                  success: (subscription) ->
                    href = "http://secure.loadmax.com/subscriptions/dashboard/"+
                    subscription[0]['id']+"?paysysid="+subscription[0]['paysysid']
                    temp += '<tr><td><b>'+company['name']+'</b><td>'
                    temp += "<td><a href="+href+"> Use </a></td></tr>"
                .done ->
                  li.push temp
              popover_text += li.join " "
              popover_text += "</table>"
              $('.mc-popover').popover(html: true, placement: 'right', content: popover_text )
              $('.mc-popover').popover("show")
        else

最佳答案

UNEXPECTED INDENT的直接含义是一行代码缩进过多,但也可能被观察为前一行发生语法错误的结果。

为了定位这个错误,您应该从清理代码开始。为了让 CoffeeScript(以及我认为的所有语言,但这还有待争论)保持可读性和可维护性,它应该被分解为小函数。事实上,您在附加代码片段底部附近有大约 8 级缩进,这使得任何错误都难以识别。

如果在将上面的高度嵌套代码分解为较小的函数后错误仍然存​​在(我怀疑它会;当您清理时问题可能会自行显现),您可以开始用 stub 替换这些函数的内容。

一旦找到有问题的 5 行代码,请专心地盯着代码,直到问题本身显现出来。

如有必要,添加咖啡。

附注 如果代码文件中 \tab 字符和 两个空格 缩进之间存在差异,我过去也遇到过此问题。因此,如果您的 IDE 允许,请启用空白显示或执行其可用的任何空白清理选项。

关于javascript - 部署 Ruby On Rails 项目时出现意外的 INDENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22719261/

相关文章:

javascript - Js 加载页面更改输入最小值

javascript - ScrollTop 到元素 - 20px

javascript - 正则表达式匹配一个数字序列和一个字符。它们之间

javascript - jQuery,从字符串中删除括号

ruby-on-rails - ActiveRecord - has_many :through, :dependent => :destroy sql 不正确

ruby-on-rails - Twilio:接收短信并处理正文内容

ruby-on-rails - Rails.application.routes.url_helpers 使 Heroku 应用程序崩溃

ruby-on-rails - 为什么我今天必须在我的命令前添加 'bundle exec'?

ruby-on-rails - 设置activeadmin gem后Rails api脚手架问题

ruby-on-rails - 按日期(或任何其他列)对 ActiveRecord 返回的数组进行排序