# Partial Static Site

**URL:** <https://www.ruby-forum.com/t/partial-static-site/121670>\
**Category:** Rails\
**Created:** [November 29, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/partial-static-site/121670 "2007-11-29T20:21:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c89c15/32.png) [@dracko](https://www.ruby-forum.com/u/dracko)\
**Post date:** [November 29, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/partial-static-site/121670/1 "2007-11-29T20:21:51Z")

</div>

I’m developing a site compound by a static part and a dynamic one.

I still use things like “link\_to(…)”, etc in the static part within  
rhtml  
files.

In the static part, I don’t have the notion of controller and model.  
Reading  
some article about the subject, I got the following situation:

- created a controller, let me call it “static”;
- put my rhtml files under app/views/static/.

Except for the “index” page, all the rest are static pages.

The problem is that I have a lot of static pages to write and it would  
be  
confuse to put all them in this directory.

For instance, if I have a menu with several submenus and each submenus  
could  
have others subsubmenus, I would like the following structure:

-app/views/static/

- menu1
  - menu1/submenu1
  - menu1/submenu2

- menu2/
  - menu2/submenu1
  - menu2/submenu2

- otherfile

I know I could do something like:  
-app/views/static/

- menu1
- menu1\_submenu1
- menu1\_submenu2

But I would prefer the other much cleaner solution.

I first tried some links like:  
link\_to =\> ‘id’ =\> ‘submenu1’

The link worked as I expected, but after noticing it didn’t work, I  
remembered that Rails would try to run the action ‘menu1’ with  
the ‘submenu1’ as a parameter, but I’m not using this parameter in this  
action.

I would not like to write an action for every view I want in a  
subdirectory…

What would be the Rails way to achieve what I want?

I want Rails to render all the remaining url after the ‘static’  
controller  
as the local url after app/views/static.

Let me know if I was not clear. Sorry for the big message, but I  
couldn’t  
make my question clear enough in a small message.

Thanks in advance,

Rodrigo.

---

<div class="post-metadata">

**Author:** ![dracko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c89c15/32.png) [@dracko](https://www.ruby-forum.com/u/dracko)\
**Post date:** [November 29, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/partial-static-site/121670/2 "2007-11-29T21:08:16Z")

</div>

Rodrigo Rosenfeld R. wrote:

> - put my rhtml files under app/views/static/.
> - menu1
> - menu1\_submenu1  
> action.  
> make my question clear enough in a small message.
> 
> Thanks in advance,
> 
> Rodrigo.

I ended up with the following solution:

in static\_controller.rb:

before\_filter :show\_static

def show\_static  
if request.request\_parameters[‘id’]

# render :template =\> request.env[‘PATH\_INFO’]

# the solution above is probably server dependent.

# The solution below is probably a better one:

```
  render :template => request.request_parameters['controller'] + '/' 

```

- 

```
  request.request_parameters['action'] + '/' +
  request.request_parameters['id']

```

end  
end

Any thoughts about this solution?

Regards,

Rodrigo.

---

<div class="post-metadata">

**Author:** ![dracko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c89c15/32.png) [@dracko](https://www.ruby-forum.com/u/dracko)\
**Post date:** [December 1, 2007, 6:49am UTC](https://www.ruby-forum.com/t/partial-static-site/121670/3 "2007-12-01T06:49:45Z")

</div>

> def show\_static  
> if request.request\_parameters[‘id’]
> 
> # render :template =\> request.env[‘PATH\_INFO’]
> 
> # the solution above is probably server dependent.
> 
> # The solution below is probably a better one:
> 
> ```
> render :template => request.request_parameters['controller'] + '/' +
> request.request_parameters['action'] + '/' +
> request.request_parameters['id']
> 
> ```
> 
> end  
> end

I suspect what you want is a custom route. Something like

map.connect ‘static/\*url\_parts’, :controller =\> “static”, :action =\>  
“show”

Have the show action of the static\_controller put the url\_parts array  
back  
together with ‘/’ into ‘menu1/submenu1’ and then process the template at  
app/views/static/menu1/submenu1.rhtml

---

<div class="post-metadata">

**Author:** ![dracko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c89c15/32.png) [@dracko](https://www.ruby-forum.com/u/dracko)\
**Post date:** [December 6, 2007, 7:42pm UTC](https://www.ruby-forum.com/t/partial-static-site/121670/4 "2007-12-06T19:42:39Z")

</div>

Cynthia K. wrote:

> I suspect what you want is a custom route. Something like
> 
> map.connect ‘static/\*url\_parts’, :controller =\> “static”, :action =\>  
> “show”
> 
> Have the show action of the static\_controller put the url\_parts array back  
> together with ‘/’ into ‘menu1/submenu1’ and then process the template at  
> app/views/static/menu1/submenu1.rhtml

Thanks, I didn’t know this trick of using arrays in routes…

Rodrigo.
