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
8
  • have you installed net-ssh gem? Commented Mar 18, 2014 at 14:07
  • Yes in did gem install net-ssh. Like I said, if I run this script from command prompt it is working. Commented Mar 18, 2014 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... Commented Mar 18, 2014 at 14:13
  • It's added to you gemfile? Just wondering since you showed us installing it to the box. Commented Mar 18, 2014 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 Commented Mar 18, 2014 at 14:16

2 Answers 2

33

You just need to add it to Gemfile like this:

gem 'net-ssh'

and run bundle install after that.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.