Question

In Rails, how can I place views in sub directories / sub folders (just to organize them), and still have them properly routed/rendered?


I want to organize some of my views under the namespace of another view. All views are under one controller.

I want

www.custom.com/controller/action/

to show the action.html view.

I want to use this url

www.custom.com/controller/action/sub_action

instead of

www.custom.com/controller/sub_action

Both are sibling actions and views under the same controller. I wish for action to render a page, and also be used as a namespace for other views.

I don't want/need to make another controller or resource.

How do I do this?

Was it helpful?

Solution

When you render in your controller, you can specify which view you want (if it's not in the conventional place for any reason).

render 'controller/action/sub_action'

or even:

render 'some_other_controller/action/sub_action'

Checkout the Rails guides on rendering

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top