thedevlpr
thedevlpr

Reputation: 1101

Render partial from sub-directory

My views directory is structured as follows:

view

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.

Upvotes: 4

Views: 8095

Answers (3)

halfbit
halfbit

Reputation: 3939

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.

Upvotes: 3

Chris Simeone
Chris Simeone

Reputation: 1185

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'

Upvotes: 8

tirdadc
tirdadc

Reputation: 4713

I don't think it's currently possible based on these github threads.

Upvotes: 3

Related Questions