Wes Gamble
2006-Jul-13 16:32 UTC
[Rails] Generic page element display initializer in a layout?
All, I''ve run into a snag. I need to handle the display of elements on my page and I want to use my Javascript event handlers on page load. However, my BODY tag is trapped in my generic layout. I''m thinking that I can put an onLoad on the BODY tag that will just call a Javascript method called initializePage() and then provide this initializePage() call in my specific page to call whatever handlers I need to in order to display things correctly. Something in the back of my head is screaming AJAX but not sure how I would get that in. Any thoughts? Wes -- Posted via http://www.ruby-forum.com/.
Wes Gamble
2006-Jul-13 17:06 UTC
[Rails] Re: Generic page element display initializer in a layout?
Wes Gamble wrote:> All, > > I''ve run into a snag. I need to handle the display of elements on my > page and I want to use my Javascript event handlers on page load. > > However, my BODY tag is trapped in my generic layout. > > I''m thinking that I can put an onLoad on the BODY tag that will just > call a Javascript method called initializePage() and then provide this > initializePage() call in my specific page to call whatever handlers I > need to in order to display things correctly. > > Something in the back of my head is screaming AJAX but not sure how I > would get that in. > > Any thoughts? > > WesFYI, this kind of Javascript scheme will work, but I think I just need to make my template smarter, so I will do that instead. WG -- Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Jul-13 19:26 UTC
[Rails] Re: Generic page element display initializer in a layout?
On Jul 13, 2006, at 10:04 AM, Wes Gamble wrote:> Wes Gamble wrote: >> All, >> >> I''ve run into a snag. I need to handle the display of elements on my >> page and I want to use my Javascript event handlers on page load. >> >> However, my BODY tag is trapped in my generic layout. >> >> I''m thinking that I can put an onLoad on the BODY tag that will just >> call a Javascript method called initializePage() and then provide >> this >> initializePage() call in my specific page to call whatever handlers I >> need to in order to display things correctly. >> >> Something in the back of my head is screaming AJAX but not sure how I >> would get that in. >> >> Any thoughts? >> >> Wes > > FYI, this kind of Javascript scheme will work, but I think I just need > to make my template smarter, so I will do that instead. > > WGWes- You can also use the content_for method to push dynamic content from your view up to the master layout. So in your normal view: <% content_for :javascript do %> <script> # blah blah more javascript <script> <% end %> So in your layout: <html> <head> <%= yield :javascript %> </head> -Ezra
Wes Gamble
2006-Jul-13 20:22 UTC
[Rails] Re: Re: Generic page element display initializer in a layout
Ezra Zygmuntowicz wrote:> On Jul 13, 2006, at 10:04 AM, Wes Gamble wrote: > >>> this >> FYI, this kind of Javascript scheme will work, but I think I just need >> to make my template smarter, so I will do that instead. >> >> WG > > > Wes- > > You can also use the content_for method to push dynamic content > from your view up to the master layout. > > So in your normal view: > > <% content_for :javascript do %> > <script> > # blah blah more javascript > <script> > <% end %> > > So in your layout: > > <html> > <head> > <%= yield :javascript %> > </head> > > > -EzraWhoa - so content_for generates a block that can then be yielded to in any of the enclosing templates? WG -- Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Jul-13 21:48 UTC
[Rails] Re: Re: Generic page element display initializer in a layout
On Jul 13, 2006, at 1:22 PM, Wes Gamble wrote:> Ezra Zygmuntowicz wrote: >> On Jul 13, 2006, at 10:04 AM, Wes Gamble wrote: >> >>>> this >>> FYI, this kind of Javascript scheme will work, but I think I just >>> need >>> to make my template smarter, so I will do that instead. >>> >>> WG >> >> >> Wes- >> >> You can also use the content_for method to push dynamic content >> from your view up to the master layout. >> >> So in your normal view: >> >> <% content_for :javascript do %> >> <script> >> # blah blah more javascript >> <script> >> <% end %> >> >> So in your layout: >> >> <html> >> <head> >> <%= yield :javascript %> >> </head> >> >> >> -Ezra > > > Whoa - so content_for generates a block that can then be yielded to in > any of the enclosing templates? > > WGWes- Yeah, pretty sweet way to push dynamic content up from the partials or templates into the layout. This is a very powerfull feature once you start playing with it. Makes your layouts much more flexible and reuseable because your normal views can specialize the layout. Cheers- -Ezra
Wes Gamble
2006-Jul-13 21:56 UTC
[Rails] Re: Re: Re: Generic page element display initializer in a la
Ezra Zygmuntowicz wrote:> On Jul 13, 2006, at 1:22 PM, Wes Gamble wrote: > >>> >>> <script> >>> -Ezra >> >> >> Whoa - so content_for generates a block that can then be yielded to in >> any of the enclosing templates? >> >> WG > > > Wes- > > Yeah, pretty sweet way to push dynamic content up from the partials > or templates into the layout. This is a very powerfull feature once > you start playing with it. Makes your layouts much more flexible and > reuseable because your normal views can specialize the layout. > > Cheers- > -EzraAs I sometimes say when I get excited - that is f-in ballz! :) WG -- Posted via http://www.ruby-forum.com/.
Seemingly Similar Threads
- Does text_field go directly to attributes hash in AR object?
- Setting a global before_filter action in application.rb
- Using <%= text_field %> within partials is problematic
- Is there QA on Rails gem releases?
- Wrap error_messages_for() call when no instance var present