Ruby on Rails-无法加载此类文件-net/ssh [英] Ruby on rails - cannot load such file -- net/ssh
问题描述
我已经为此苦苦挣扎了几天.
I've been struggling on this for a few days now..
当我尝试从视图中调用帮助器中的方法来执行ssh时,它将引发该错误.
When I try to call a method in a helper from a view to do ssh, it throws that error.
在加载以下文件时发生此错误:net/ssh"
"This error occurred while loading the following files: net/ssh"
但是当我将代码复制到test.rb
文件并从提示符ruby test.rb
执行它时,它可以完美地连接.
But when I copy the code into a test.rb
file and execute it from prompt ruby test.rb
it connects flawlessly.
可能是什么问题?我在另一台计算机上尝试过,结果相同.
What could be the problem ? I tried on another computer and same result.
非常感谢您,这就像我完成项目之前的最后一步!
Thank you very much this is like the last step before I can complete my project!
此致
application_helper.rb
:
module ApplicationHelper
def title(value)
unless value.nil?
@title = "#{value} | Eucc"
end
end
def execute
require 'rubygems'
require 'net/ssh'
@hostname = "smtlmon02"
@username = "gcaille"
@password = "qaz1234"
@cmd = "ls -al"
@cmd2 = "sudo su - -c 'ls;date'"
ssh = Net::SSH.start(@hostname, @username, :password => @password)
res = ssh.exec!(@cmd)
res2 = ssh.exec!(@cmd2)
ssh.close
File.open("output.txt", 'w') {|file| file.write(res2)}
end
end
推荐答案
您只需要像这样将其添加到Gemfile中:
You just need to add it to Gemfile like this:
gem 'net-ssh'
然后运行捆绑安装.
这篇关于Ruby on Rails-无法加载此类文件-net/ssh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!