Partial Static Site

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.

Rodrigo Rosenfeld Rosas wrote:

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.

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.

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

Cynthia Kiser wrote:

  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

Thanks, I didn't know this trick of using arrays in routes...

Rodrigo.