# Unable to make observe\_field work

**URL:** <https://discuss.rubyonrails.org/t/unable-to-make-observe-field-work/43471>\
**Category:** rubyonrails-talk\
**Created:** [June 14, 2009, 9:18pm UTC](https://discuss.rubyonrails.org/t/unable-to-make-observe-field-work/43471 "2009-06-14T21:18:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 14, 2009, 9:18pm UTC](https://discuss.rubyonrails.org/t/unable-to-make-observe-field-work/43471/1 "2009-06-14T21:18:35Z")

</div>

I can't make it work.

\<%= text\_field\_tag :friend %\>

\<%= observe\_field :friend, :url =\> friendships\_url, :on =\> :click %\>

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

Raises the error:Can't find variable Form.

The generated html is:

\<input id="friend" name="friend" type="text" /\>

\<script type="text/javascript"\> //\<![CDATA[new Form.Element.EventObserver('friend', function(element, value) {new Ajax.Request('[http://mysite.com/friendships](http://mysite.com/friendships)’, {asynchronous:true, evalScripts:true, parameters:value + '&authenticity\_token=' + encodeURIComponent('...edited...')})}) //]]\> \</script\>

---

<div class="post-metadata">

**Author:** ![Mauricio\_Linhares1](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@Mauricio\_Linhares1](https://discuss.rubyonrails.org/u/Mauricio_Linhares1)\
**Post date:** [June 14, 2009, 9:20pm UTC](https://discuss.rubyonrails.org/t/unable-to-make-observe-field-work/43471/2 "2009-06-14T21:20:41Z")

</div>

The:

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

Should appear BEFORE the:

\<%= observe\_field :friend, :url =\> friendships\_url, :on =\> :click %\>

It's usually placed at your page's \<header\> section.

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 14, 2009, 9:38pm UTC](https://discuss.rubyonrails.org/t/unable-to-make-observe-field-work/43471/3 "2009-06-14T21:38:42Z")

</div>

Just to save people 1hr of head banging:

This DOES NOT WORK: (data is submitted to ApplicationController/index!!! \<%= observe\_field :friendship\_accessibility, :url =\> friendship\_url(friendship), :on =\> :click, :with =\> :accessibility %\>

This works: (all options are compulsory) \<%= observe\_field :friendship\_accessibility, :url =\> {:controller =\> 'friendships', :action =\> 'update', :id =\> friendship}, :on =\> :click, :with =\> :accessibility, :method =\> :update %\>

Is that a bug? Why can't the observe\_field and Rails routing mechanism recognize the restful route?

---

<div class="post-metadata">

**Author:** ![Mukund](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Mukund](https://discuss.rubyonrails.org/u/Mukund)\
**Post date:** [June 15, 2009, 6:04am UTC](https://discuss.rubyonrails.org/t/unable-to-make-observe-field-work/43471/4 "2009-06-15T06:04:27Z")

</div>

You don't have an :update specified on the parameters for observe\_field. Assuming you don't want to render anything, do a render :nothing=\>true in the controller.
