0

Hi.

I'm just trying out Ruby on Rails, and I'm trying to create some application that takes a hostname from the user and then checks if it is connectible through Net::SSH and if it is, it should check if a file is present.

Quite simple, and I also almost reached goal. But I can't seem to implement what should happen if Net::SSH.start fails?

I just get a big Rails error page with param dumps and stuff, but actually I'd just like to do a render :text => 'Hey couldn't connect dewd' or something.

How is that doable? Do I have to make my own error page of some kind?
Thank you.

Edited by Excizted: Stopped my Net::SSH becoming a smiley lol

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Excizted
0

Hi.

I'm just trying out Ruby on Rails, and I'm trying to create some application that takes a hostname from the user and then checks if it is connectible through Net::SSH and if it is, it should check if a file is present.

Quite simple, and I also almost reached goal. But I can't seem to implement what should happen if Net::SSH.start fails?

I just get a big Rails error page with param dumps and stuff, but actually I'd just like to do a render :text => 'Hey couldn't connect dewd' or something.

How is that doable? Do I have to make my own error page of some kind?
Thank you.

Hope this would help:

around_filter :catch_exceptions

private
def catch_exceptions
yield
rescue => exception
logger.debug "Caught exception! #{exception}"
render :text => 'Hey couldn't connect'
raise
end

0

I'm able to do what I want to achieve with your code, but it also overrides all other errors, making it hard to debug - also seems to override my 'Insufficient admin priviliges' system.

Is there some way to tune the functionality so that it render :text if it is the Net::SSH related error, or yield if not?

Thank you :)

0

I'm able to do what I want to achieve with your code, but it also overrides all other errors, making it hard to debug - also seems to override my 'Insufficient admin priviliges' system.

Is there some way to tune the functionality so that it render :text if it is the Net::SSH related error, or yield if not?

Thank you :)

You can have this filter to only to a particular action

before_filter :catch_exceptions, :only => [:action_name]

0

Thank you, works like a charm.
Unfortunately the action SSH is called from, is giantic with lots of different functionality depending on post params, but I'll just make a new action dedicated for the SSH connection and then call that action from the original action.

Thanks again ;)

0

Thank you, works like a charm.
Unfortunately the action SSH is called from, is giantic with lots of different functionality depending on post params, but I'll just make a new action dedicated for the SSH connection and then call that action from the original action.

Thanks again ;)

That's great to hear :)

0

Actually it seems that the error is raised from my original action although moving it... Guess I'll have to live with that.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.