16

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
Gagan Gami
  • 10,121
  • 1
  • 29
  • 55
Guillaume Caillé
  • 393
  • 2
  • 6
  • 20
  • have you installed net-ssh gem? – MikeZ Mar 18 '14 at 14:07
  • Yes in did gem install net-ssh. Like I said, if I run this script from command prompt it is working. – Guillaume Caillé Mar 18 '14 at 14:10
  • I changed require 'net/ssh' for require 'net-ssh' and same results: cannot load such file -- net-ssh and I did again : C:\Users\guillaume.caille>gem install net-ssh Successfully installed net-ssh-2.8.0 1 gem installed Installing ri documentation for net-ssh-2.8.0... Installing RDoc documentation for net-ssh-2.8.0... – Guillaume Caillé Mar 18 '14 at 14:13
  • It's added to you gemfile? Just wondering since you showed us installing it to the box. – agmcleod Mar 18 '14 at 14:15
  • Could you post the full stacktrace of the error? Also helper is not the place for this method. You should probably move it to model or some utility – usha Mar 18 '14 at 14:16
  • It is not in the file named "gemfile" in the root of my project. Do I have to add it this way ? gem 'net-ssh', '~> 2.8.0' – Guillaume Caillé Mar 18 '14 at 14:18
  • Well the full stacktrace is 10 000 char too long to be posted here – Guillaume Caillé Mar 18 '14 at 14:21
  • Thank you !! I added this line into my gemfile and did bundle install. it added net-ssh and it is now working. – Guillaume Caillé Mar 18 '14 at 14:31

2 Answers2

32

You just need to add it to Gemfile like this:

gem 'net-ssh'

and run bundle install after that.

Sergey Moiseev
  • 2,953
  • 2
  • 24
  • 28
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.