# Unable to make observe\_field work

**URL:** <https://www.ruby-forum.com/t/unable-to-make-observe-field-work/170244>\
**Category:** Rails\
**Created:** [June 14, 2009, 11:18pm UTC](https://www.ruby-forum.com/t/unable-to-make-observe-field-work/170244 "2009-06-14T23:18:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 14, 2009, 11:18pm UTC](https://www.ruby-forum.com/t/unable-to-make-observe-field-work/170244/1 "2009-06-14T23: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:

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 14, 2009, 11:22pm UTC](https://www.ruby-forum.com/t/unable-to-make-observe-field-work/170244/2 "2009-06-14T23:22:10Z")

</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 section.

- 

Maurício Linhares  
[http://codeshooter.wordpress.com/](http://codeshooter.wordpress.com/) | [http://twitter.com/mauriciojr](http://twitter.com/mauriciojr)

On Sun, Jun 14, 2009 at 6:18 PM, Fernando

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 14, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/unable-to-make-observe-field-work/170244/3 "2009-06-14T23:23:09Z")

</div>

Thanks Mauricio! So stupid of me!

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 14, 2009, 11:53pm UTC](https://www.ruby-forum.com/t/unable-to-make-observe-field-work/170244/4 "2009-06-14T23:53:09Z")

</div>

Do I need to set a respond\_to block in the update action of the  
controller for rjs? I don’t understand what’s missing, and the rails api  
is rather thin on the subject.

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 14, 2009, 11:38pm UTC](https://www.ruby-forum.com/t/unable-to-make-observe-field-work/170244/5 "2009-06-14T23: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:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 15, 2009, 8:05am UTC](https://www.ruby-forum.com/t/unable-to-make-observe-field-work/170244/6 "2009-06-15T08:05:19Z")

</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.

On Jun 15, 2:53 am, Fernando P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [June 15, 2009, 3:46pm UTC](https://www.ruby-forum.com/t/unable-to-make-observe-field-work/170244/7 "2009-06-15T15:46:04Z")

</div>

Mukund wrote:

> 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.  
> The problem is that it’s ApplicationController#index that processes the  
> submitted data. I don’t understand why. The url is correctly formed.
