Forum: Ruby on Rails Best way to use partial rendering in global layout

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-14 01:00
I have a global layout in application.rhtml and I'd like to render a
partial template within it.

Currently, I have this:

<%= render (:partial => 'side_nav') %>

but it seems to be looking in the controller specific view directory.

What is the best way to do handle controller - global partial rendering?

Wes
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-14 01:08
ANSWER:
Create a "shared" directory under app/views and do:

<%= render ( :partial => 'shared/side_nav' ) %>

THANKS DAVE THOMAS!

Wes

Wes Gamble wrote:
> I have a global layout in application.rhtml and I'd like to render a
> partial template within it.
>
> Currently, I have this:
>
> <%= render (:partial => 'side_nav') %>
>
> but it seems to be looking in the controller specific view directory.
>
> What is the best way to do handle controller - global partial rendering?
>
> Wes
Ddffdd431166f9abb724004bdbe56f8c?d=identicon&s=25 Lucifron (Guest)
on 2006-03-14 11:07
(Received via mailing list)
What if you want to use a global partial most of the time, but sometimes
want
to override it?

Would it add any value to have rails check the controller specific
directory
first, and then automatically look in shared/global/layouts/whatever if
not
found? Seems intuitive to me, but may just mean higher complexity with
no
real gain.
--
View this message in context:
http://www.nabble.com/Best-way-to-use-partial-rend...
Sent from the RubyOnRails Users forum at Nabble.com.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-14 16:53
I think that's how it works now, actually.

I scaffolded a new controller and the default layout that was generated
got used until I removed it, and then the global one got used.

Wes

Lucifron wrote:
> What if you want to use a global partial most of the time, but sometimes
> want
> to override it?
>
> Would it add any value to have rails check the controller specific
> directory
> first, and then automatically look in shared/global/layouts/whatever if
> not
> found? Seems intuitive to me, but may just mean higher complexity with
> no
> real gain.
> --
> View this message in context:
> 
http://www.nabble.com/Best-way-to-use-partial-rend...
> Sent from the RubyOnRails Users forum at Nabble.com.
Ddffdd431166f9abb724004bdbe56f8c?d=identicon&s=25 Lucifron (Guest)
on 2006-03-14 19:06
(Received via mailing list)
Wes Gamble wrote:
>
> I think that's how it works now, actually.
>
> I scaffolded a new controller and the default layout that was generated
> got used until I removed it, and then the global one got used.
>
> Wes
Layouts work this way, yes, but not partials.

--
View this message in context:
http://www.nabble.com/Best-way-to-use-partial-rend...
Sent from the RubyOnRails Users forum at Nabble.com.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-14 19:12
That's right.

I don't know - I think someone would find a good use for that feature
with partials.

Wes

Lucifron wrote:
> Wes Gamble wrote:
>>
>> I think that's how it works now, actually.
>>
>> I scaffolded a new controller and the default layout that was generated
>> got used until I removed it, and then the global one got used.
>>
>> Wes
> Layouts work this way, yes, but not partials.
>
> --
> View this message in context:
> 
http://www.nabble.com/Best-way-to-use-partial-rend...
> Sent from the RubyOnRails Users forum at Nabble.com.
This topic is locked and can not be replied to.