How to change background image by using same layout

Roseanne Zhang wrote:

I am using a layout to all pages. However, I want change the background image in different views. The background images are difined in a CSS file. <body> tag is in the layout file. I can difine diffrent class of body to have different bg image.

So far, I think my question can change to how to pass class name to the layout file?
  

That depends on what you want the change in background image to be based on

If you want a different body class for each controller (and your controller_name doesn't contain
any spaces), you could do this:

    <body class="<%= controller.controller_name %>">

To set it based on action, you can use:

       <body class="<%= controller.action_name %>">

If you want a different background image depending upon the combination of controller and
action called, you can set a @bodyclass variable in each method, and then pass that along to
appliaction.rhtml

    <body class="<%= @bodyclass %>">

There could be other (possibly even more elegant) ways of doing this, of course :wink:

~gwendy