eval(hyperlink) question

42 views
Skip to first unread message

Dave Castellano

unread,
Aug 28, 2014, 9:15:21 AM8/28/14
to rubyonra...@googlegroups.com
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

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

Colin Law

unread,
Aug 28, 2014, 10:33:36 AM8/28/14
to rubyonra...@googlegroups.com
On 28 August 2014 14:14, Dave Castellano <li...@ruby-forum.com> wrote:
> 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.

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

Christopher R. Maden

unread,
Aug 28, 2014, 10:52:05 AM8/28/14
to rubyonra...@googlegroups.com
On 08/28/2014 08:14 AM, Dave Castellano wrote:
> 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.

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
--
Chris Maden, text nerd <URL: http://crism.maden.org/ >
Surround hate and force it to surrender.
GnuPG fingerprint: DB08 CF6C 2583 7F55 3BE9 A210 4A51 DBAC 5C5C 3D5E

Dave Castellano

unread,
Aug 28, 2014, 1:32:27 PM8/28/14
to rubyonra...@googlegroups.com
Christopher R. Maden wrote in post #1156206:
Thanks! That did the trick.

Left most of q = eval out of post Colin.

Dave

Dave Castellano

unread,
Aug 29, 2014, 8:33:40 AM8/29/14
to rubyonra...@googlegroups.com
Dave Castellano wrote in post #1156219:
> Christopher R. Maden wrote in post #1156206:
>> On 08/28/2014 08:14 AM, Dave Castellano wrote:
>>> 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,

Norbert Melzer

unread,
Aug 29, 2014, 2:32:18 PM8/29/14
to Rails Mailinglist


Am 29.08.2014 14:33 schrieb "Dave Castellano" <li...@ruby-forum.com>:
>
> Dave Castellano wrote in post #1156219:
> > Christopher R. Maden wrote in post #1156206:
> >> On 08/28/2014 08:14 AM, Dave Castellano wrote:
> >>> 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:

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.

>
> 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
>
> --
> Posted via http://www.ruby-forum.com/.
>

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9f70371fc4d5ba77a6ce43191d76df9b%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages