About Sinatra

main.rb:

require ‘sinatra’

get ‘/’ do
haml :index
end

views/index.haml:
%a{:href => “www.google.com”}link

when i run this program and click link in html page, it will direct to
localhost/www.google.com when i expected just www.google.com.

so what is the problem and how to solve this problem ?

On 06/14/2012 10:08 AM, Bin J. wrote:

%a{:href => “www.google.com”}link

when i run this program and click link in html page, it will direct to
localhost/www.google.com when i expected just www.google.com.

so what is the problem and how to solve this problem ?

Try using a valid URL.

Hint: if you drop the protocol prefix, the URL is interpreted as being
relative to your current location.

The problem is with href url you are using.
If you’ll try to put it to the HTML directly (without
Sinatra or HAML):

<a href="www.google.com">link</a>

You will get same result (in fact browser simply treats this
URL as relative to current one). The correct way for you is:

%a{:href => "//www.google.com"}link

Or with specifying protocol directly

%a{:href => "http://www.google.com"}link

NOTICE, that if you are not specifying a protocol, e.g.
//foobar.com then browser will automagcally use the protocol
of your current URL.

On Thu, Jun 14, 2012 at 10:08 AM, Bin J. [email protected] wrote:

%a{:href => “www.google.com”}link

when i run this program and click link in html page, it will direct to
localhost/www.google.com when i expected just www.google.com.

so what is the problem and how to solve this problem ?


Posted via http://www.ruby-forum.com/.


Sincerely yours,
Aleksey V. Zapparov A.K.A. ixti
FSF Member #7118
Mobile Phone: +34 677 990 688
Homepage: http://www.ixti.net
JID: [email protected]

*Origin: Happy Hacking!