View Full Version : rhtml including rhtml?
spm
November 3rd, 2005, 11:37 AM
Hi. I'm fairly new at this. I'm trying to convert a J2EE app that I have...to learn Ruby.
I am not doing rails, as the app does not have DB, mostly accesses data through SOAP and http.
I am using currently WEBrick as an Httpserver (small and easy).
Now the glaring problem that I have...there does not seem to be anyways to something like
<% include="other.rhtml" %>
Anyway to do this? erb??? I saw something about eruby.import("...") but cant seem to find it?
Rails is obviously doing something similar, whats the trick? Thanks!
bluetechnx
November 3rd, 2005, 02:28 PM
ERuby can be found here:
http://www.modruby.net/en/index.rbx/eruby/whatis.html
I don't know exactly what your trying to include. I would assume a header/footer or some template onto each page. I don't know if include works that way...
From this source code listing:
http://raa.ruby-lang.org/gonzui/markup/eruby/examples/test.rhtml
It would appear that Eruby.import("other.rthml"); provides the functionality you want :) sweet, I never knew that. Please tell me if I'm wrong :)
spm
November 3rd, 2005, 04:17 PM
ERuby can be found here:
http://www.modruby.net/en/index.rbx/eruby/whatis.html
I don't know exactly what your trying to include. I would assume a header/footer or some template onto each page. I don't know if include works that way...
From this source code listing:
http://raa.ruby-lang.org/gonzui/markup/eruby/examples/test.rhtml
It would appear that Eruby.import("other.rthml"); provides the functionality you want :) sweet, I never knew that. Please tell me if I'm wrong :)
Yes thats exactly what I want...but I dont want to intalls a module yet. Not even running apache.
So far I have come with with something like this:
module HtmlUtils
def HtmlUtils.import( filename, bindings )
rhtml = File.read('html/BigPictureDetails.rhtml')
rhtml.untaint
erb = ERB.new(rhtml, $SAFE, '%')
str = erb.result(bindings)
return str
end
end
Which I call from my rhtml:
index.rhtml
<% require 'HtmlUtils' %>
<h1>Index page</h1>
<%= Date.today() %>
<% name = "myTest" %>
<%= HtmlUtils::import('test.rhtml',binding()) %>
test.rhtml
<H2><%= name %></h2>
But calling index.rhtml seems to supercede what I currently had in the page, ie I only get the output of test.rhtml coming out...seems to flush out index.
Documentation is poor to say the least on ERB.new( ... ) (I guess coming from Java where the Javadoc is very complete)
Any ideas?
I know I can put $SAFE in, but what else? and what does it do?
Any help?
spm
December 7th, 2005, 02:55 PM
Because of the lack of support (documentation and online), our project will not be using ruby.
I did not want to have to use/install Apache + module to get this to work, this was the first stumbling block of many.
Hopefully Ruby will mature, but right now, it is not ready for the corporate world, and if that does not occur, it has no chance of being taken seriously.
steve_d555
December 7th, 2005, 03:32 PM
I think you were looking for layout (http://api.rubyonrails.com/classes/ActionController/Layout/ClassMethods.html#M000077)
It allows you to change the layout per controller or method.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.