在我的控制器中,我正在尝试执行一个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
当我手动运行此脚本时。它按预期发送邮件。
您必须进行
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..
(或)
尝试重新启动服务器,有时它会修复它。