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? I am new with RoR, please help! Thanks a lot! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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? > > 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 <body class="<%= @body_class%>"> in the layout. Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 ;) ~gwendy --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Roseanne Zhang
2006-Sep-26 19:02 UTC
Re: How to change background image by using same layout
Thanks Fred! I actually figured it out after posting the question. I know, I am still very far away from good on RoR. :( Thanks again! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Roseanne Zhang
2006-Sep-26 19:05 UTC
Re: How to change background image by using same layout
gwendy wrote:> ~gwendyHey, gwendy You gave more flexible solution, great!!! Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Terry Donaghe
2006-Sep-26 19:14 UTC
Re: How to change background image by using same layout
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 Zhang
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> Thanks Fred!
>
> I actually figured it out after posting the question. I know, I am still
> very far away from good on RoR. :(
>
> Thanks again!
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--
Terry (TAD) Donaghe
http://www.rubynoob.com
http://www.tadspot.com
--~--~---------~--~----~------------~-------~--~----~
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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---