How to change background image by using same layout

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. 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?

I am new with RoR, please help!

Thanks a lot!

Roseanne Z. 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. 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?

I am new with RoR, please help!

Thanks a lot!

The layout has access to controller instance variables in the same way
that views do, so for example you can have

in the layout.

Fred

Roseanne Z. 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. 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

Thanks Fred!

I actually figured it out after posting the question. I know, I am still
very far away from good on RoR. :frowning:

Thanks again!

gwendy wrote:

~gwendy

Hey, gwendy

You gave more flexible solution, great!!!

Thanks!

You can use scriptaculous to dynamically change the css style properties
of
any element.

Something like:

Element.setStyle(‘mydiv’, {backgroundColor:‘blue’})

While it doesn’t directly address your problem, I think you could use a
variation of this to solve your problem. I wrote about this here:

http://rubynoob.com/articles/2006/09/06/how-to-change-css-styles-on-the-fly-with-ajax-rjs-and-prototype

I see you’ve solved the problem… How did you fix it?

Terry

On 9/26/06, Roseanne Z. [email protected] wrote:

Posted via http://www.ruby-forum.com/.


Terry (TAD) Donaghe
http://www.rubynoob.com
http://www.tadspot.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs