# Rails use case

**URL:** <https://rubytalk.org/t/rails-use-case/17566>\
**Category:** ruby-talk\
**Created:** [11 April 2005 18:24 UTC](https://rubytalk.org/t/rails-use-case/17566 "2005-04-11T18:24:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ritchie](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@ritchie](https://rubytalk.org/u/ritchie)\
**Post date:** [11 April 2005 18:24 UTC](https://rubytalk.org/t/rails-use-case/17566/1 "2005-04-11T18:24:41Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![ritchie](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@ritchie](https://rubytalk.org/u/ritchie)\
**Post date:** [11 April 2005 19:24 UTC](https://rubytalk.org/t/rails-use-case/17566/2 "2005-04-11T19:24:40Z")

</div>

So just found render\_file is this the answer to all my caching  
questions ? 🙂

R

---

<div class="post-metadata">

**Author:** ![Douglas\_Livingstone](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@Douglas\_Livingstone](https://rubytalk.org/u/Douglas_Livingstone)\
**Post date:** [11 April 2005 21:38 UTC](https://rubytalk.org/t/rails-use-case/17566/3 "2005-04-11T21:38:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ritchie](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@ritchie](https://rubytalk.org/u/ritchie)\
**Post date:** [11 April 2005 20:34 UTC](https://rubytalk.org/t/rails-use-case/17566/4 "2005-04-11T20:34:39Z")

</div>

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

class SwitcherController \< ApplicationController

&nbsp;&nbsp;def index  
&nbsp;&nbsp;&nbsp;&nbsp;@p = @params["path"]  
&nbsp;&nbsp;&nbsp;&nbsp;@acc = Account.find\_all  
&nbsp;&nbsp;&nbsp;&nbsp;render\_file("/experiments/rail\_test/public/content/#{@p}/index.rhtml",false)  
&nbsp;&nbsp;end

&nbsp;&nbsp;def pagecontroller  
&nbsp;&nbsp;&nbsp;&nbsp;@wow = "wow it worked"  
&nbsp;&nbsp;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 🙂

Thanks for any info.

R

---

<div class="post-metadata">

**Author:** ![ritchie](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@ritchie](https://rubytalk.org/u/ritchie)\
**Post date:** [12 April 2005 01:14 UTC](https://rubytalk.org/t/rails-use-case/17566/5 "2005-04-12T01:14:38Z")

</div>

> 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](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
