【问题标题】:Syntax Error when trying to run rails runner on test environment尝试在测试环境中运行 rails runner 时出现语法错误
【发布时间】:2017-08-01 04:40:39
【问题描述】:

我创建了一个用 rails runner 运行的脚本。我在本地对其进行了测试,它工作得很好,但是在远程服务器上(它已部署到 AWS)它会引发以下错误:

/home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1
/lib/rails/commands/runner.rb:62: 
syntax error, unexpected tIDENTIFIER, expecting end-of-input

这里有完整的错误信息:

/home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1/lib/rails/commands/runner.rb:62:in `eval': /home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1/lib/rails/commands/runner.rb:62: unknown regexp options - rt (SyntaxError)
/home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1/lib/rails/commands/runner.rb:62: syntax error, unexpected tIDENTIFIER, expecting end-of-input
/script/content_update.rb
                               ^
    from /home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1/lib/rails/commands/runner.rb:62:in `<top (required)>'
    from /home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1/lib/rails/commands/commands_tasks.rb:128:in `require'
    from /home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1/lib/rails/commands/commands_tasks.rb:128:in `require_command!'
    from /home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1/lib/rails/commands/commands_tasks.rb:95:in `runner'
    from /home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/ubuntu/my-project/vendor/bundle/ruby/2.1.0/gems/railties-4.1.14.1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

知道可能是什么问题吗?

【问题讨论】:

    标签: ruby-on-rails ruby amazon-web-services amazon-ec2


    【解决方案1】:

    你需要像这样执行命令:

    rails runner script/content_update.rb
    

    script/content_update.rb 是脚本的正确路径。

    当您像/script/content_update.rb Rails 那样指定它时,在错误的位置搜索它却找不到它。当找不到文件时,Rails 将字符串视为Ruby 脚本并尝试执行它,然后引发这个奇怪的异常。

    【讨论】:

    • 这引导我朝着正确的方向前进,我试图从根目录运行rails runner。它抛出了一个完全没有意义的黑暗小巷错误undefined local variable or method &lt;script name here&gt; for main:Object (NameError)...
    猜你喜欢
    • 2019-04-28
    • 2023-01-16
    • 2014-10-16
    • 2021-02-25
    • 1970-01-01
    • 2021-07-29
    • 2013-01-01
    • 2012-05-26
    • 1970-01-01
    相关资源
    最近更新 更多