# Using ajax and layouts

**URL:** <https://www.ruby-forum.com/t/using-ajax-and-layouts/83117>\
**Category:** Rails\
**Created:** [March 17, 2006, 1:24pm UTC](https://www.ruby-forum.com/t/using-ajax-and-layouts/83117 "2006-03-17T13:24:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Claus\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47c2d/32.png) [@Claus\_G](https://www.ruby-forum.com/u/Claus_G)\
**Post date:** [March 17, 2006, 1:24pm UTC](https://www.ruby-forum.com/t/using-ajax-and-layouts/83117/1 "2006-03-17T13:24:15Z")

</div>

Hi.

I copied the layout-example from agile web dev. in rails. When I want  
to use ajax to create a search field including

\<%= javascript\_include\_tag "prototype" %\>

does’nt work when I include the line in my  
app/views/layout/demo.rhtml. Name of controller is demo\_controller.rb.

The search-field is in app/views/demo/observer.rthml and I have to  
include the above mentioned line in this file to “ajax-enable” the  
search-field. Should’nt it be possible to include it from a  
layout-file?

regards  
Claus

---

<div class="post-metadata">

**Author:** ![Claus\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47c2d/32.png) [@Claus\_G](https://www.ruby-forum.com/u/Claus_G)\
**Post date:** [March 17, 2006, 1:48pm UTC](https://www.ruby-forum.com/t/using-ajax-and-layouts/83117/2 "2006-03-17T13:48:39Z")

</div>

Try this:

 \<%= javascript\_include\_tag :defaults %\>

On 3/17/06, Claus G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The search-field is in app/views/demo/observer.rthml and I have to

–  
Tom D.

[http://blog.atomgiant.com](http://blog.atomgiant.com)  
[http://gifthat.com](http://gifthat.com)

---

<div class="post-metadata">

**Author:** ![Claus\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47c2d/32.png) [@Claus\_G](https://www.ruby-forum.com/u/Claus_G)\
**Post date:** [March 17, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/using-ajax-and-layouts/83117/3 "2006-03-17T18:40:18Z")

</div>

> Try this:
> 
> \<%= javascript\_include\_tag :defaults %\>

Thank you so much! 🙂

How come “prototype” does not work?

regards  
Claus

---

<div class="post-metadata">

**Author:** ![Claus\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47c2d/32.png) [@Claus\_G](https://www.ruby-forum.com/u/Claus_G)\
**Post date:** [March 17, 2006, 11:19pm UTC](https://www.ruby-forum.com/t/using-ajax-and-layouts/83117/4 "2006-03-17T23:19:01Z")

</div>

> Your include “prototype” should have successfully included the  
> prototype library. I tested it on mine and it rendered:
> 
> which should work.

Well, the thing is that you are once again correct in your assumption.  
I first did the change to :default and opened the page in firefox’s  
javascript-console. There I found the “fabulous four” mentioned below.

> 

Then I changed back to “prototype” in the layout-rhtml and it still  
works. So either I spelled it wrong or some caching in the browser or  
lighttpd took place.

regards  
Claus

---

<div class="post-metadata">

**Author:** ![Claus\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e47c2d/32.png) [@Claus\_G](https://www.ruby-forum.com/u/Claus_G)\
**Post date:** [March 17, 2006, 9:56pm UTC](https://www.ruby-forum.com/t/using-ajax-and-layouts/83117/5 "2006-03-17T21:56:50Z")

</div>

Hi Claus,

Glad that worked for you.

Your include “prototype” should have successfully included the  
prototype library. I tested it on mine and it rendered:

which should work.

I am guessing that what you are trying to do depends on some of the  
helper libraries as well. If you view the source of your generated  
page you will see all of these get included with the :defaults:

Tom

On 3/17/06, Claus G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Claus
> 
> > > does’nt work when I include the line in my  
> > > Rails mailing list
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Tom D.

[http://blog.atomgiant.com](http://blog.atomgiant.com)  
[http://gifthat.com](http://gifthat.com)
