How to serve rhtml files under /public, not /app/views?

Dear all,

I’m running Instantrails on Windows, and I’m wondering if I can put
some ruby code to html files under the /public folder. (rather than
those application code under the /app folder)

Do I need to tune something in mongrel so that it can parse those
rhtml files with a ruby intepreter?

Thanks,
Akira

Akira wrote:

Dear all,

I’m running Instantrails on Windows, and I’m wondering if I can put
some ruby code to html files under the /public folder. (rather than
those application code under the /app folder)

Do I need to tune something in mongrel so that it can parse those
rhtml files with a ruby intepreter?

Thanks,
Akira

Could I ask WHY you would want to do this before I try and answer it?

Hi,

'coz the /app structure in the rails framework is very application
centric, and it could be useful if i can have some (not too much) code
in the ®html files.

for instance, i’m creating a corporate brochure type of website and
like 80% of the stuffs’re static pages by the designer. i tend to put
the designer’s work in /public. even then, on those static pages, what
if i need something as simple as <%=Time.now.to_s%>… it would be
useful if i can just parse a minimal amount of ruby code there.

Thanks.

On Sep 20, 9:31 pm, Jean N. [email protected]

in some cases yes, client side js would suffice…
but my Time.now example might not be a good one… there’re still times
when i would rather have server side scripts available on rhtml files.

is there a way? or really every piece of code has to be in /app?

thanks.

On Sep 20, 11:04 pm, Mike P. [email protected]

Would client-side Javascript be sufficient?

mike

Akira wrote:

Hi,

'coz the /app structure in the rails framework is very application
centric, and it could be useful if i can have some (not too much) code
in the ®html files.

for instance, i’m creating a corporate brochure type of website and
like 80% of the stuffs’re static pages by the designer. i tend to put
the designer’s work in /public. even then, on those static pages, what
if i need something as simple as <%=Time.now.to_s%>… it would be
useful if i can just parse a minimal amount of ruby code there.

Akira wrote:

Hi,

'coz the /app structure in the rails framework is very application
centric, and it could be useful if i can have some (not too much) code
in the ®html files.

for instance, i’m creating a corporate brochure type of website and
like 80% of the stuffs’re static pages by the designer. i tend to put
the designer’s work in /public. even then, on those static pages, what
if i need something as simple as <%=Time.now.to_s%>… it would be
useful if i can just parse a minimal amount of ruby code there.

Thanks.

Okay this makes sense, but I think it’s a lot more problematic then you
would believe. When you code an MVC application, all views are supposed
to be protected / encapsulated and only accessible by the controller,
never directly to the public.

The reason for this is that the idea of the controller is to ‘setup’ the
information needed by the view (even if that setup is to just forward
the request through). Putting a view in a publicly accessible location
breaks this modeling as now people can just bookmark the page and call
it later. If this page is called directly you’ll get all kinds of rails
errors leaking to the client app.

As for actually doing it, far be it from me to keep information from
you…

render :file => path_to_file in your controller with the path being
absolute will do the trick for you.

My advice though, keep the rails way as it’s safe, find a way to have
your deployment process, or a rake task, scour a directory the content
providers create (I.E. client developers) and put the files into the
proper views directories. This will save you many headaches in the
future.

thanks Jean, yes i understand your point and i agree it’s better to do
it the proper way.

one other reason this question came to my mind is that i think i’ve
seen on some website (though i don’t recall the exact site names now)
with url’s ending with a “.rhtml”, and i thought maybe this can be
like jsp / asp / php it could be used casually, on a page by page
basis as well.

with your solution “render :file => path” the controller is still the
central point of the request. i’m thinking, technically, can i have
something like http://domain/somefolders/somepage.rhtml ? i mean, not
thru the rails routing but rather somefolders/sompage.rhtml are simply
within /public. (though not a good practice, but this should be
technically feasbile shouldn’t it?)

Thanks.

On Sep 20, 11:37 pm, Jean N. [email protected]

My advice though, keep the rails way as it’s safe, find a way to have
your deployment process, or a rake task, scour a directory the content
providers create (I.E. client developers) and put the files into the
proper views directories. This will save you many headaches in the
future.

P.S. Sorry for being long winded… but hey… that’s just may way. :wink:

If you want your URLs to look a certain way, that’s normally entirely
the concern of the routing, generally configured in routes.rb. You could
certainly have routes set up that allow requests to end in “.rhtml”
(although why you’d want to I don’t know), but they’d still be routed to
controllers. Because that’s how Rails MVC works.

But you want a URL that looks like
http://domain/somefolders/somepage.rhtml” to just map to a file on disk
in public/somefolders.somepage.rhtml, and then just call that “rhtml”
file kind of like PHP works?

I don’t think you want Rails. There might be some way to make that
happen in Rails, but it’s pretty antithetical to the entire architecture
of Rails. If you really want to do that, perhaps there’s another ruby
web architecture (other than Rails) that will do that. Personally, I
think it’s probably a bad idea though.

If you want to let your designers edit the .rhtml views themselves
directly, that could be fine, but leave them in /app/views! Why not?

Jonathan

Akira wrote:

thanks Jean, yes i understand your point and i agree it’s better to do
it the proper way.

one other reason this question came to my mind is that i think i’ve
seen on some website (though i don’t recall the exact site names now)
with url’s ending with a “.rhtml”, and i thought maybe this can be
like jsp / asp / php it could be used casually, on a page by page
basis as well.

with your solution “render :file => path” the controller is still the
central point of the request. i’m thinking, technically, can i have
something like http://domain/somefolders/somepage.rhtml ? i mean, not
thru the rails routing but rather somefolders/sompage.rhtml are simply
within /public. (though not a good practice, but this should be
technically feasbile shouldn’t it?)

Thanks.

On Sep 20, 11:37 pm, Jean N. [email protected]

Akira wrote:

i’m thinking, technically, can i have
something like http://domain/somefolders/somepage.rhtml ? i mean, not
thru the rails routing but rather somefolders/sompage.rhtml are simply
within /public. (though not a good practice, but this should be
technically feasbile shouldn’t it?)

Thanks.

This looks like the (IMHO deprecated) mod_ruby way of having a mime-type
handler in the apache setup parsing any URL ending in .rhtml and letting
the server deal with the converting of the template file into html.

I think you’re getting way off track with what you want to do here as
that methodology seems much more “Ruby CGI” then a “Rails” solution. Try
looking at the mod_ruby plugin for apache to make sure. It may allow you
to do this, I know of no way in Mongrel to handle your need. I checked
the Mongreal documentation and nothing I scanned jumped out at me as
being able to do what you want.

sorry.

Akira wrote:

Dear all,

I’m running Instantrails on Windows, and I’m wondering if I can put
some ruby code to html files under the /public folder. (rather than
those application code under the /app folder)

Do I need to tune something in mongrel so that it can parse those
rhtml files with a ruby intepreter?

Thanks,
Akira

Akira,

What you want is to use eruby and bypass Rails. See this chapter from
the PickAxe:

http://ruby-doc.org/docs/ProgrammingRuby/html/web.html

Here is a post from Zed S. about eruby with Mongrel:

http://rubyforge.org/pipermail/mongrel-users/2006-June/000459.html

From that, I gather it may be easier simply to set up Apache as the
front end to handle your .rhtml files.

David B. Williams
http://www.cybersprocket.com

Hi all, thanks.

i agree with all your comments; and yes i think something like
mod_ruby probably answers my original question.

and yes that probably isn’t a rails issue to begin with, it’s really
all about interpreting ruby code by the web server. not that i really
need it to work in that way, but i was just so curious to know if it’s
technically feasible.

Thanks anyway, cheers!

On Sep 21, 1:29 am, Jean N. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs