eval(hyperlink) question

Hi,

The hyperlink below is being evaluated to "questions/www.somewhere.com":

q = eval(question) # Converts (evaluates) the question string from the database back into code.

question =" ... from a light source is equal to the <a href='www.somewhere.com'>index of refraction</a> (n) divided by the distance (in meters) of the light rays..."

Can anyone point me in the right direction as to why "questions" is being prepended to the route and how to avoid that from happening.

Thanks, Dave Castellano, MD

What is the content of q after assigning the eval to it? As you have described it I would have expected that to generate a runtime error: 1.8.7-p374 :003 > question ="... from a light source is equal to the <a> href='www.somewhere.com'>index of refraction</a> (n) divided by the distance (in meters) of the light rays..." => "... from a light source is equal to the <a> href='www.somewhere.com'>index of refraction</a> (n) divided by the distance (in meters) of the light rays..." 1.8.7-p374 :004 > eval(question) SyntaxError: (eval):1:in `irb_binding': compile error (eval):1: syntax error, unexpected tDOT3 ... from a light source is equal ...    ^

Colin

This is a basic HTML problem, not a Rails one.

Your link is a relative link to the file “www.somewhere.com” in the current directory, *not* a link to the site www.somewhere.com. You need an explicit method, e.g.:

<a href='http://www.somewhere.com/'>

~Chris

Christopher R. Maden wrote in post #1156206:

Dave Castellano wrote in post #1156219:

Christopher R. Maden wrote in post #1156206:

Can anyone point me in the right direction as to why "questions" is being prepended to the route and how to avoid that from happening.

This is a basic HTML problem, not a Rails one.

Your link is a relative link to the file “www.somewhere.com” in the current directory, *not* a link to the site www.somewhere.com. You need an explicit method, e.g.:

<a href='http://www.somewhere.com/'>

~Chris

A quick follow up question?

I would like to open the link in a new window but the following opens the link on the current tab:

question = "<a href='http://www.cnn.com' target= '_blank'>index of refraction</a> What is the vergence of the light rays in the image at reference plane (y), #{distance_in_cm.round(2)} cm from the light source?"

It seems to be ignoring the target= '_blank'

Thanks again,

Dave

Dave Castellano wrote in post #1156219:

Christopher R. Maden wrote in post #1156206:

Can anyone point me in the right direction as to why “questions” is being prepended to the route and how to avoid that from happening.

This is a basic HTML problem, not a Rails one.

Your link is a relative link to the file “www.somewhere.com” in the current directory, not a link to the site www.somewhere.com. You need an explicit method, e.g.:

~Chris

A quick follow up question?

I would like to open the link in a new window but the following opens the link on the current tab:

You can’t do that with guarantee, some browsers don’t even know about windows or tabs (links, lynx) others are configurable in that matter.