Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render partial from sub-directory

My views directory is structured as follows:

view

  • by domain
    • domain1
      • user_mailer
        • nav
          • _menu.html.haml
        • apply.html.haml
        • welcome.html.haml

Is there a way to render the partial from apply.html.haml without specifying the full path? I read somewhere else I could do render :partial => "./nav/menu" but it isn't working for me.

like image 892
Rafa Avatar asked Dec 25 '22 10:12

Rafa


2 Answers

Use the full path in the render method.

For example, if you have the following directory structure ...

app
| views
|--» landing
|----» main_template.html.erb
|----» desktop
|------» _home.html.erb
|----» mobile
|------» _home.html.erb

... and main_template which calls render is found underapp/views/landing, then calls to render would look like this ...

render partial: 'landing/desktop/home'

render partial: 'landing/mobile/home'

like image 193
Chris Simeone Avatar answered Jan 13 '23 18:01

Chris Simeone


You can use append_view_path in your controller. I use it like that:

class DemoController < SiteController
.
.
    before_filter do
        append_view_path Rails.root.join("domain/domain1/user_mailer")
    end 
...

Of course this only works if you have different view/partial names in these directories.

like image 28
halfbit Avatar answered Jan 13 '23 18:01

halfbit