# Problem with observe\_field

**URL:** <https://www.ruby-forum.com/t/problem-with-observe-field/64102>\
**Category:** Rails\
**Created:** [June 22, 2006, 1:41am UTC](https://www.ruby-forum.com/t/problem-with-observe-field/64102 "2006-06-22T01:41:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pratik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4bbf92/32.png) [@pratik](https://www.ruby-forum.com/u/pratik)\
**Post date:** [June 22, 2006, 1:41am UTC](https://www.ruby-forum.com/t/problem-with-observe-field/64102/1 "2006-06-22T01:41:03Z")

</div>

Hi folks,

# I have following in my view :

\<%= select 'theme', "id", Theme.find\_all.collect {|t| [t.name, t.id] }, { :prompt =\> 'Select a theme' } %\>

\<%= observe\_field(  
:theme\_id,  
:update =\> :my\_style,  
:url =\> { :action =\> :themelookup, :id =\> @space,},  
:with =\> ‘theme\_id’)  
%\>

 \<%= text\_area 'my', 'style', :cols =\> '65', :rows=\>'10' %\>
=========================================

Basically I’m updating the text area based on selection made from  
selection box. This works well. But in firefox, if I edit the value in  
textbox and try to make a different selection from the selection box,  
it doesnt update. This works well in IE !? Any pointers ?

Thanks,  
Pratik

---

<div class="post-metadata">

**Author:** ![pratik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4bbf92/32.png) [@pratik](https://www.ruby-forum.com/u/pratik)\
**Post date:** [June 22, 2006, 8:33am UTC](https://www.ruby-forum.com/t/problem-with-observe-field/64102/2 "2006-06-22T08:33:43Z")

</div>

Pratik wrote:

> %\>
> 
> \<%= text\_area 'my', 'style', :cols =\> '65', :rows=\>'10' %\>
> =========================================
> 
> Basically I’m updating the text area based on selection made from  
> selection box. This works well. But in firefox, if I edit the value in  
> textbox and try to make a different selection from the selection box,  
> it doesnt update. This works well in IE !? Any pointers ?

Two things to look at with your observe field call:

1. You should be updating userfoo rather than my\_style
2. You don’t need to use the :with option

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![pratik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4bbf92/32.png) [@pratik](https://www.ruby-forum.com/u/pratik)\
**Post date:** [June 22, 2006, 8:36am UTC](https://www.ruby-forum.com/t/problem-with-observe-field/64102/3 "2006-06-22T08:36:52Z")

</div>

That’s how I got that working. But still dont understand why I cannot  
update “my\_style”. It works well in IE.

Also, when I update “userfoo”, I need to write html code in my  
controller. What are the common ways to keep my controller clean to  
avoid this kind of cases ?

Thanks for the reply Mark.

-Pratik

---

<div class="post-metadata">

**Author:** ![pratik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4bbf92/32.png) [@pratik](https://www.ruby-forum.com/u/pratik)\
**Post date:** [June 22, 2006, 8:40am UTC](https://www.ruby-forum.com/t/problem-with-observe-field/64102/4 "2006-06-22T08:40:02Z")

</div>

Look into RJS templates. They will let you write these calls without  
regenerating any HTML in the controller actions.

[http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates](http://www.codyfauser.com/articles/2005/11/20/rails-rjs-templates)

Jason

---

<div class="post-metadata">

**Author:** ![pratik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4bbf92/32.png) [@pratik](https://www.ruby-forum.com/u/pratik)\
**Post date:** [June 22, 2006, 9:23am UTC](https://www.ruby-forum.com/t/problem-with-observe-field/64102/5 "2006-06-22T09:23:07Z")

</div>

Just ordered Cody’s book on RJS 🙂

---

<div class="post-metadata">

**Author:** ![pratik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4bbf92/32.png) [@pratik](https://www.ruby-forum.com/u/pratik)\
**Post date:** [June 22, 2006, 8:05am UTC](https://www.ruby-forum.com/t/problem-with-observe-field/64102/6 "2006-06-22T08:05:25Z")

</div>

Anyone :-s ?
