我创建了一个用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>'
知道问题可能是什么?
答案 0 :(得分:1)
您需要执行以下命令:
rails runner script/content_update.rb
script/content_update.rb
是您脚本的正确路径。
当您指定它时,/script/content_update.rb
Rails
会在错误的位置搜索它,但无法找到它。找不到文件时,Rails
将字符串视为Ruby
脚本并尝试执行它,然后引发这个奇怪的异常。