Rails use case

Hi there, I'm new to rails, started today really, and am wondering how
to shoehorn my existing php setup into it.

I have non-programmers, trusted content editors, who need to edit a
standard hierarchy of html with possibly embedded ruby by me, they do
so every day by ftp etc. It seems wrong for them to have access to the
views directory or any non public rails dir. So, one solution, which is
close to my current php solution, is to have a controller which loads
(r)html from the public directory, does any necessary substitutions
etc. This seems straight forward, e.g.

http://localhost:3000/mydispatchcontroller?path=/public/mydir/index.rhtml

However, it would seem a good idea to use the rails existing caching
system etc and the general infrastructure, is this possible for rhtml
outside the views dirs? Or is this kind of much more free format
application structure a bad fit for rails? Free format in the sense
that the users could add new directories and content to the public
dirs, for me to fill out with specific programmatic stuff at a later
date. Really, I'd like views to be added dynamically and hierarchically
organised within a public dir?? What are the possibilities?

Thanks

Ritchie

So just found render_file is this the answer to all my caching
questions ? :slight_smile:

R

What does your current PHP do?

How does it do it?

What do your current URLs look like?

It sounds like you want your templates to call your controller. That's
somewhat anti-MVC, because in MVC it is the controller which calls the
template. By default Rails will load the template with the same name
as the current action for you. You can call code easily from the
template by putting code in the relevant helper module, but by putting
anything more than view code in there you'll probably not be using
Rails as much as you can.

Douglas

···

On Apr 11, 2005 7:24 PM, ritchie <ritchie@ipowerhouse.com> wrote:

Hi there, I'm new to rails, started today really, and am wondering how
to shoehorn my existing php setup into it.

ok, so far so good. Thanks Tony. I have the following code

class SwitcherController < ApplicationController

  def index
    @p = @params["path"]
    @acc = Account.find_all
    render_file("/experiments/rail_test/public/content/#{@p}/index.rhtml",false)
  end

  def pagecontroller
    @wow = "wow it worked"
  end
end

So it get's content from whatever the supplied path is to the
controller. Works, however, I only have one controller, and each
possible page could have it's own "controller", i.e. somewhere where I
can set up new vars for the page itself. I don't think I can include
model references in the view for example. So, is it possible for the
page to call it's own controller, an inversion of the usual process,
page gets called from "SwitcherController", then the page does

<% pagecontroller %>

so that after the call

<%=@wow%> is defined??

Ok, that's all I want :slight_smile:

Thanks for any info.

R

What does your current PHP do?
How does it do it?

My current PHP is a framework that creates the menu system from the
directory structure. So if my content editors add a new directory with
an index.php then the next client to connect has the new content
available. I don't have to get involved in the editing of simple pages,
so it's wiki-ish and has a number of zope features like acquisition of
pages. I'm trying to recreate that in Rails as it works well in
practice and my users are familiar with the ideas.

My current URLS look like what I posted earlier

http://localhost/apps/app/switcher.php?path=/Account/Personal

would render index.php in the Account/Personal directory (or
recursively in directories above if not found in Account (zopeish)).
The switcher.php includes the relevant file, however the index.php is
still fully functional in terms of I can get at the db and have as much
complicated code in the view as I want. This seems to be what I can't
do in rails in the view. As an aside each one of my pages can have it's
own controller a mirroring index.prc which can be optionally included
before the index.php for hardcore php you may not want the user to see.

That's
somewhat anti-MVC, because in MVC it is the controller which calls the
template

Yes, I thought it may hence my query on if this is a valid use case.
However, I'm not sure that rails can't do what I want yet. I suspect it
can easily. The problem is my pages are added by users when they feel
like it, and I need to optionally add controller like functionality if
it requires specialised behaviour. Actually maybe what I'm lookig for
is using a rails "helper" on the page??? All I'm trying to do is get
access to the model and/or specialised code from the page without a
priori knowledge in the controller itself, i.e. is there some other way
of embedding arbitrary code in the view other than from a controller?
Hope that makes sense?

Ritchie