Ruby on rails - 无法加载这样的文件--net / ssh

时间:2022-08-27 09:47:43

I've been struggling on this for a few days now..

我已经在这几天挣扎了......

When I try to call a method in a helper from a view to do ssh, it throws that error.

当我尝试从视图中调用帮助器中的方法来执行ssh时,它会抛出该错误。

"This error occurred while loading the following files: net/ssh"

“加载以下文件时发生此错误:net / ssh”

But when I copy the code into a test.rb file and execute it from prompt ruby test.rb it connects flawlessly.

但是当我将代码复制到test.rb文件并从提示ruby test.rb执行它时,它完美连接。

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!

非常感谢,这就像我完成项目之前的最后一步!

Regards,

问候,

application_helper.rb:

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

2 个解决方案

#1


24  

You just need to add it to Gemfile like this:

你只需要将它添加到Gemfile中,如下所示:

gem 'net-ssh'

and run bundle install after that.

然后运行bundle install。

#2


0  

You may need to restart your IDE as well. I had this problem with Net::SFTP and Sergey Moiseev's solution worked great, but I had to restart my IDE after the bundle install.

您可能还需要重新启动IDE。我有Net :: SFTP这个问题,谢尔盖Moiseev的解决方案工作得很好,但我必须在安装捆绑后重启我的IDE。

#1


24  

You just need to add it to Gemfile like this:

你只需要将它添加到Gemfile中,如下所示:

gem 'net-ssh'

and run bundle install after that.

然后运行bundle install。

#2


0  

You may need to restart your IDE as well. I had this problem with Net::SFTP and Sergey Moiseev's solution worked great, but I had to restart my IDE after the bundle install.

您可能还需要重新启动IDE。我有Net :: SFTP这个问题,谢尔盖Moiseev的解决方案工作得很好,但我必须在安装捆绑后重启我的IDE。