Errno :: ENOENT(没有这样的文件或目录 - )

时间:2013-02-11 15:05:02

标签: ruby-on-rails ruby ruby-on-rails-3

在我的控制器中,我正在尝试执行ruby脚本:

def mymethod
  variable = `ruby /home/user/Test.rb`
  exec variable
  raise "Failed: #{variable}" unless variable.blank?
end

Test.rb脚本出现在上述路径中,即使这样我也会收到错误:

Errno::ENOENT (No such file or directory - )

Test.rb内容:

require 'rubygems'
require 'net/smtp'
require 'pp'
require 'mysql'
require 'yaml'
message = "MESSAGE_END
G Name <MyEmailAddress>
To: G Name <MyEmailAddress>
Subject: SMTP e-mail test
This is a test mail"
Net::SMTP.start('webserver') do |smtp|
smtp.send_message message, 'EmailAddress', 'EmailAddress'
end

当我手动运行此脚本时。它按预期发送邮件。

1 个答案:

答案 0 :(得分:1)

你必须

require 'open-uri'

所以,

require '/home/user/Test.rb'  
require 'open-uri'  # sometimes without this line, we get the exact error message in ruby on rails..

(或)

尝试重新启动服务器,有时会修复它..