html output from required file

M

mark

Can someone please tell me why this doesn't work?

contents of test.rb
-------------------------
class Test
def draw
%> <b>draw method!</b> <%
end
end

contents of test.rhtml
----------------------------
<%
require "test.rb"
Test.new.draw
%>

when Test class is in the same file it works but when it is 'require'd
I get errors.
Thanks for any tip
 
J

Jakub Hegenbart

mark napsal(a):
Can someone please tell me why this doesn't work?

contents of test.rb
-------------------------
class Test
def draw
%> <b>draw method!</b> <%
end
end

contents of test.rhtml
----------------------------
<%
require "test.rb"
Test.new.draw
%>

when Test class is in the same file it works but when it is 'require'd
I get errors.
Thanks for any tip

Perhaps because it's not supposed to work? "Require" is _not_ a textual
include, it is equivalent to running the file through the Ruby parser,
compiling methods into AST and adding these mthods into Ruby "object
dictionary". The Ruby parser doesn't understand those "%>","<%"-tags you
are using in your test.rb file. ;-)

Do you have any special intent, trying to perform output this way? I
suppose it's not necessary at all.

Jakub
 
M

mark

Hi,
Yes, I want my class to be able to output html without a bunch of ugly
'puts' lines.
I guess I'm looking for a way to have eruby handle the required file
instead of ruby.

Any help is appreciated.
 
M

mark

I guess I just answered my own question. I should have been using
ERuby.import
d'oh!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,186
Messages
2,570,998
Members
47,587
Latest member
JohnetteTa

Latest Threads

Top