Forum: Ruby html output for variables

C038403192dcc27dcb9fc91b3dc9dc9d?d=identicon&s=25 Ferdous ara (ferdous)
on 2014-03-27 21:24
Hi,
To create a graph i am passing table like bellow


htmloutput='
            <td class=\"graphable\" id=\"absolute:data:data1:\">9</td>
<td class=\"graphable\" id=\"absolute:data:data1:\"  >10</td>
'

now problem is, the value comes from variables like this :
 #{hash["1"]}

but when i use this variables inside ' ', its coming as a text like


htmloutput='
            <td class=\"graphable\"
id=\"absolute:data:data1:\">#{hash["1"]}</td>  <td class=\"graphable\"
id=\"absolute:data:data1:\"  >#{hash["1"]}</td>
'
how do i convert it to value ??

i might be very silly but i am not seeing any light!!
thanks for help
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-03-27 21:40
You normally need to use double-quoted strings to use interpolation.
However, since your string contains double-quotes, I would recommend
using a heredoc or using %Q

htmloutput=%Q|
            <td class=\"graphable\"
id=\"absolute:data:data1:\">#{hash["1"]}</td>  <td class=\"graphable\"
id=\"absolute:data:data1:\"  >#{hash["1"]}</td>
|
C038403192dcc27dcb9fc91b3dc9dc9d?d=identicon&s=25 Ferdous ara (ferdous)
on 2014-03-27 23:21
Hi
Thanks

i just tried that, its works but problem is,
its removing "" from html example when its generating the page, if i see
view source , i see this

<td class=graphable id=absolute:data:data1>9</td>

but in the html page it should come like this
<td class="graphable id=absolute:Retail:Voice:CDR">9</td>

does it make sense ??

reason, to create a graph by using this gaphable, that needs to be
inside ""

please advise.. i am stuck ..
C038403192dcc27dcb9fc91b3dc9dc9d?d=identicon&s=25 Ferdous ara (ferdous)
on 2014-03-27 23:29
Some thing like perl

 $htmloutput.=
         "<tr><td>RX-bytes</td><td class=\"graphable\"
id=\"counter:$dev:rx-bytes\">".$ifd[0]."</td></tr>\n"
        ."<tr><td>RX-packets</td><td class=\"graphable\"
id=\"counter:$dev:rx-packets\">".$ifd[1]."</td></tr>\n"
."</table>\n"
        ."<hr><pre>".$out."</pre>\n";



same type of concept for ruby ...

hope it make sense ..
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-03-29 00:54
The interpolation should be fine, as demonstrated below. Presumably
whatever you're using to create the html file is removing your quotes,
but you haven't given any information on that process.

1:0> hash = {'1' => 'test'}
=> {"1"=>"test"}
2:0> htmloutput=%Q|
3:0"             <td class="graphable"
4:0" id="absolute:data:data1:">#{hash["1"]}</td>  <td class="graphable"
5:0" id="absolute:data:data1:"  >#{hash["1"]}</td>
6:0" |
7:0> puts htmloutput

            <td class="graphable"
id="absolute:data:data1:">test</td>  <td class="graphable"
id="absolute:data:data1:"  >test</td>
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.