newbie question about rendering partials and rhtml


im not sure if i am on the right path here, so i figured i would ask.

Basically, all of my pages have the same header and footer, and i was
wondering if there was some way i could reference this from the rhtml file?

from what i have read on partial and template rendering, this is done in the
controller, but in my case, the header and footer are static, so there is no
logic. Basically, I am just trying to minimize the number of places i need
to edit in case i make a change to my header or footer (i.e. if i add a
link, i would really like to just update 1 file, rather than do it in all of
my views).

Is this possible? thanks!

Have a look at layouts, that is precisely what they are for. For example, if you create an html skeleton, call it application.rhtml and place it in the layouts folder (in views/), the app will call it by default. In the area where you want the controller-generated output to go, simply place this call:

<% yield %>

and the magic will take place.

Hi Dave,

I read up on layouts, ( )

and it made me wonder why you cant specify a specific layout inside an
action? i tried placing the: layout "standard-layout" inside one of my
action def's, but i ended up with an error.

it this not possible?

Dave Goodchild wrote:

The "layout 'standard-layout'" call is a class method call that sets the layout for the whole controller.

To specify a specific layout for an action, pass it to render:

def fooaction
   # do something
   render :layout => 'super-special-layout'


gmoniey wrote:

thanks for clearing that up...i have another question...this may be
more of a design question....our existing website has 2 templates, and
we determine which one to show based on screen size, which is
determined through javascript...i.e.

<script type="text/javascript">
<!-- Begin
        if(screen.width > xxx)
                 window.location = "template1";

        else {
// End -->

now i am trying to determine how to do this....basically all of my
actions behave the same, except they have a different layout...

but i am a bit doesnt seem like i can do this on the
server side...i.e. in the controller....or in the .rhtml
should i redirect with a id specifying which template? (i.e. set the
window.location to specify the id in the url, and then base the
template on that?

im not sure if i have been very if this is confusing....let
me know...and i'll try and clear it up...

I guess it depends how much of the difference between the two templates
is presentational is handled by css. If so, the javascript can still do
it’s thing. The rhtml layouts should only contain structural
information (ie html/xhtml). Clarify a little more?

the two layouts are actually very different...different images,
different static text, different tables, div's etc...

i have been thinkin about this more and more..and it seems like the
best way to do it would be something like this:

<script type="text/javascript">
<!-- Begin
         if(screen.width > xxx)
                  window.location = "";

        else {
  // End -->

and have the action handle which template will be shown from there on
out (since this really only need to be figured out the first time the
page loads), worried about the case where the user wanted
to go back to the homepage...i.e., i would need
a way to ensure that the javascript is run again...