Log in

View Full Version : Ruby Help - Outputting HTML



mburt
01-13-2007, 02:23 AM
I'm learning Ruby :)
Okay. To the point. I'm making a script that will repitively write out HTML tags...
Like a for-loop. It serves no real purpose, but I'm trying to figure out how to do it.
This is what I have

<% innertext = "Hello World!"
tag = "<i>"+innertext+"</i>\n"
max = 4
print(innertext*max) %>
It appears as normal text? Why won't it interpret the Ruby code?

djr33
01-13-2007, 02:59 AM
Why won't what interpret it? A PHP server setup wouldn't be expted to, an ASP server setup might try and fail.... Just not sure what you mean.
Is this desktop based?

mburt
01-13-2007, 03:06 AM
The browser is supposed to be able to interperet Ruby code with these tags:

<&#37; %>

But unfortunately it doesn't work. I'm saving my html docs as .htm, and that may have something to do with it. Other than that, I'm pretty much in the dark.

djr33
01-13-2007, 03:07 AM
Judging from PHP, generally, I'd say be sure that .htaccess is configured to sent through ruby for whatever .ext's you want.
I don't really know how it should work... can't say much more.

mburt
01-13-2007, 03:12 AM
I think it has something to do with ASP files.. But again I'm not sure. Thanks anyways though.

thetestingsite
01-13-2007, 03:19 AM
Not sure if it is related, but I read somewhere that ruby files need to have one of the following extensions:

rb, rbx, or rhtml

But then again, I'm not sure about this.

mburt
01-13-2007, 03:22 AM
Hmm... rb, and rbx are for executable files (like exe, but it isn't. Well, sort of :p) I'll try rhtml.

djr33
01-13-2007, 04:40 AM
ASP may conflict, yes. It's the same open/close commands.

shachi
01-18-2007, 04:11 PM
ruby?? HTML?? mburt do you mean rails? If so, then, I think you should change this:



<&#37; innertext = "Hello World!"
tag = "<i>"+innertext+"</i>\n"
max = 4
print(innertext*max) %>


to:



<% innertext = "Hello World!"
tag = "<i>"+innertext+"</i>\n"
max = 4
print(tag*max) %>

Klondike
01-24-2007, 08:58 PM
You might also try changing your <&#37; %> tag to <%= %>. The extra equals sign means that you want the result of the block to be outputted as text. Without it, Ruby just assumes you're doing pure logic processing and aren't intending to output anything.

Twey
01-24-2007, 09:44 PM
Yes, but the call to print() should output anyway.