# Reference to Prototype missing?

**URL:** <https://www.ruby-forum.com/t/reference-to-prototype-missing/185713>\
**Category:** Rails\
**Created:** [March 24, 2010, 11:16pm UTC](https://www.ruby-forum.com/t/reference-to-prototype-missing/185713 "2010-03-24T23:16:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [March 24, 2010, 11:16pm UTC](https://www.ruby-forum.com/t/reference-to-prototype-missing/185713/1 "2010-03-24T23:16:05Z")

</div>

I added the following to a new.html.erb file:  
\<%= button\_to\_function “ShowList” do |page|  
page[:vendor\_droplist].toggle  
end  
%\>  
I ran the Rails application and got consecutive popups:

Caption: RJS error:  
Body: ReferenceError: $ is not defined

Caption: The page at [http://localhost:3000](http://localhost:3000) says:  
Body: $(“vendor\_droplist”).toggle

Could it be that a reference to Prototype is missing in the generated  
code? If so, where do it stick it at the Rails level so that it’s  
generated every time a test a new change?

I’m running Rails 2.3.5, Ruby 1.8.6, WinXP-Pro/SP3, Firefox 3.6.2,  
MySQL 5.0.37-community-nt, Mongrel

Thanks in Advance,  
Richard

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [March 25, 2010, 10:45am UTC](https://www.ruby-forum.com/t/reference-to-prototype-missing/185713/2 "2010-03-25T10:45:33Z")

</div>

After thinking about this problem a little more, I concluded that I  
needed in import prototype.js somehow. I originally thought that was  
automatic, and I’d like to make automatic.

Right now my problematic new.html.erb file in incorporated in the app  
by expenses.htmt.erb, which contains:  
\<%= stylesheet\_link\_tag ‘scaffold’ %\>

So I think I need to add something like:  
\<%= javascript\_link\_tag “javascript” %\>  
\<%= javascript\_link\_tag “prototype” %\>  
\<%= script\_link\_tag “prototype” %\>

Unfortunately, all my guesses were rejected by ERB. So I’m scouring  
my Ajax on Rails book and the web for an example. At the same time,  
I’d greatly appreciate whatever guidance anyone may care to offer.

Best wishes,  
Richard

On Mar 24, 6:15 pm, RichardOnRails

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [March 25, 2010, 11:28am UTC](https://www.ruby-forum.com/t/reference-to-prototype-missing/185713/3 "2010-03-25T11:28:52Z")

</div>

Problem solved, finally (by Ajax on Rails, after adjustment to Rails  
my 2.3.5).

Solved by adding \<%= javascript\_include\_tag :defaults %\>  
to app\views\layouts\expenses.html.erb

I have skimmed Ajax on Rails many times, treating it as a reference-  
source rather that as a textbook. But today I stated a the beginning  
of the Prototype chapter and has a solution in minutes. Whew!

On Mar 24, 6:15 pm, RichardOnRails
