Forum: Ruby on Rails eval(hyperlink) question

Be2b7277cff8516117cbd7a33df7b03a?d=identicon&s=25 Dave Castellano (dcastellano1)
on 2014-08-28 15:14
Hi,

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

q = eval(question) # Converts the question string from the database back
into code.
      formatted = {
        question:       q["question"],
        ...
     }
 end

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
4c6bde00168d595053c09aac7e487f8e?d=identicon&s=25 Colin Law (Guest)
on 2014-08-28 16:34
(Received via mailing list)
On 28 August 2014 14:14, Dave Castellano <lists@ruby-forum.com> wrote:
> 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
F068460bbdbd01e1f62b6e6e6959d6a6?d=identicon&s=25 Christopher R. Maden (Guest)
on 2014-08-28 16:52
(Received via mailing list)
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
--
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
Be2b7277cff8516117cbd7a33df7b03a?d=identicon&s=25 Dave Castellano (dcastellano1)
on 2014-08-28 19:31
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
> --
> 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

Thanks!  That did the trick.

Left most of q = eval out of post Colin.

Dave
Be2b7277cff8516117cbd7a33df7b03a?d=identicon&s=25 Dave Castellano (dcastellano1)
on 2014-08-29 14:33
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'.  Is this a single quotes
inside double quotes issue?

Thanks again,

Dave
1a4ff0766a653c62e0dab34bacda9873?d=identicon&s=25 Norbert Melzer (Guest)
on 2014-08-29 20:32
(Received via mailing list)
Am 29.08.2014 14:33 schrieb "Dave Castellano" <lists@ruby-forum.com>:
> >> current directory, *not* a link to the site www.somewhere.com.  You
need
> 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.

> 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-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk...
.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.