Ruby on rails - cannot load such file — net/ssh

我们两清 提交于 2019-12-22 03:25:15

问题


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.

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

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!

Regards,

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

回答1:


You just need to add it to Gemfile like this:

gem 'net-ssh'

and run bundle install after that.




回答2:


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.



来源:https://stackoverflow.com/questions/22481691/ruby-on-rails-cannot-load-such-file-net-ssh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!