List Info

Thread: Template "specialisation"




Template "specialisation"
user name
2006-09-07 07:48:15
Hi Bart,

The way I would do it is to get rid of the partials from
your controller 
and put them in the views. Keep the layout 'mydefault' at
the top of 
your WelcomeController as you have it. Your 'mydefault'
layout should 
look something like:

header stuff....
<%= render :partial => "welcome" %>
<%= content_for_layout %>
footer stuff..

The above layout will always render the
"welcome" partial for all 
actions. You don't need the before filter. For your contact
view, you 
can include whatever you want in its .rhtml view file. So
contact.rhtml 
can have this in it:
<% render :partial => "contact" %>

I'm not sure why you would even need the partial. Just put
the contents 
directly in contact.rhtml in your views folder.

Best Regards,

Tamim



Bart Braem wrote:
> I want to use a sitewide default template and use a
specific version in some
> controllers to have a good DRY approach to my layout.
Those controllers
> should add a little bit more HTML before rendering the
results of the
> actions, in order to avoid copying the entire
sitelayout every time.
> How can I do that? Currently my code is like this:
>
> class WelcomeController < ApplicationController
>         #before_filter :show_options
>         layout 'mydefault'
>
>         def contact
>                 render :partial =>
"contact"
>         end
>
>         private 
>                 def show_options
>                         render :partial =>
"welcome"
>                 end
> end
>
> This only shows the app/views/welcome/_contact.rhtml
page. It does not show
> the layout (that does work in other controllers where I
don't use these
> things). If I then enable the before_filter (is that
the right usage, it
> does not feel like that) then it only shows the
> app/views/welcome/_welcome.rhtml page, which is not
what I want either. 
>
> So how should I do this? How should I have this
controller use the
> layout 'mydefault', render the _welcome partial
before every method and
> also render the contact partial when the contact action
is called? 
>
> I really think I'm not using the right tools here,
especially before_filter
> seems a bit wrong here.
>
> Thanks for your help,
> Bart
>
>
> >
>
>
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )