# Testing validity of URL

**URL:** <https://www.ruby-forum.com/t/testing-validity-of-url/121533>\
**Category:** Rails\
**Created:** [November 28, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/testing-validity-of-url/121533 "2007-11-28T19:18:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [November 28, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/testing-validity-of-url/121533/1 "2007-11-28T19:18:12Z")

</div>

I am in early development of my first RoR project. I am following  
Agile Web D. with Rails and am trying to adopt their best  
practices ideas, specifically making use of the test suite and  
Subversion.

I wish to validate a URL entered into a data entry field. I found  
some code that does just that:  
[http://www.igvita.com/blog/2006/09/07/validating-url-in-ruby-on-rails/](http://www.igvita.com/blog/2006/09/07/validating-url-in-ruby-on-rails/)  
. I want to test it in my code.

It won’t validate with WEbrick. I figured that Webrick just can’t  
reach out into the Internet, but I’m not sure of that. I think that  
it might work if I were to use Apache. The instructions in the book  
that deal with Apache are in a section on deployment. They suggest  
deploying early and often. Sounds good to me. I thought I’d try to  
deploy to another area of my Fedora 7 machine.

I’ve installed Mongrel and Capistrano. When I installed Mongrel, I  
notice that it comes up on port 3000, just as WEbrick does.  
Capistrano deploys to ports 8000 and 8001. Before the book talks  
about connecting Apache and Mongrel, it calls for a test: curl -I  
[http://erie.lakeinfoworks.com:8000](http://erie.lakeinfoworks.com:8000). I don’t get a connection and I’m  
not sure what to do about it.

As I see it, one of my options is to deploy to a real remote server.  
I have one, but I’m not sure that it supports Ruby. Another is to  
find a tutorial that will teach me how to use my local server as  
though it were a remote.

Any suggestions? Thanks.

---

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [November 29, 2007, 12:05am UTC](https://www.ruby-forum.com/t/testing-validity-of-url/121533/2 "2007-11-29T00:05:17Z")

</div>

On Nov 28, 2007 10:17 AM, Joulupukki A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I wish to validate a URL entered into a data entry field. I found  
> some code that does just that: [Validating URL/URI in Ruby on Rails - igvita.com](http://www.igvita.com/blog/2006/09/07/validating-url-in-ruby-on-rails/)  
> . I want to test it in my code.

That code throws all kinds of errors when I tried it as shown.

> It won’t validate with WEbrick. I figured that Webrick just can’t  
> reach out into the Internet, but I’m not sure of that.

The request to validates the URL is outbound, and has nothing to do  
with what server you’re running it on.

Try a simpler version, say just returning something like this:  
Net::HTTP.get\_response(URI.parse(‘[http://example.com](http://example.com)’)).code  
and build out from there.

## HTH!

Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![alake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f04885/32.png) [@alake](https://www.ruby-forum.com/u/alake)\
**Post date:** [November 29, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/testing-validity-of-url/121533/3 "2007-11-29T19:38:22Z")

</div>

Before the book (Agile Web Programming with Rails) talks about  
connecting Apache and Mongrel, it calls for a test: curl -I  
[http://erie.lakeinfoworks.com:8000](http://erie.lakeinfoworks.com:8000). I don’t get a connection and I’m  
not sure what to do about it.

I found that I needed to start mongrel with “mongrel\_rails  
cluster::start” instead of “mongrel\_rails start -B”. When I did this,  
curl gives me the desired positive response. I’ve added the code to  
the Apache configuration file as prescribed in my tutorial, including  
the following code:  
\<Proxy balancer://mongrel\_cluster\>  
BalancerMember [http://127.0.0.1:8000](http://127.0.0.1:8000)  
BalancerMember [http://127.0.0.1:8001](http://127.0.0.1:8001)  
  
I got a “connection refused” error. I’ve been stumbling around  
(because I really don’t know what I’m doing) and chaged the 127.0.0.1  
to 10.0.0.4 which is how my machine is defined in /etc/hosts. Now I  
get a “Status: 500 Internal Server Error Content-Type: text/html”  
error when I try to run my Rails program.

I realize at this point that I no longer have an RoR problem, but a  
network configuration problem. However, I have this problem only  
within the context of RoR and I suspect that others, if they haven’t  
had it, may get it. Hopefully, if I’m able to resolve it, others may  
be helped, too.
