# How to get around observe\_field 'template missing' error?

**URL:** <https://www.ruby-forum.com/t/how-to-get-around-observe-field-template-missing-error/91496>\
**Category:** Rails\
**Created:** [April 9, 2007, 9:18pm UTC](https://www.ruby-forum.com/t/how-to-get-around-observe-field-template-missing-error/91496 "2007-04-09T21:18:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [April 9, 2007, 9:18pm UTC](https://www.ruby-forum.com/t/how-to-get-around-observe-field-template-missing-error/91496/1 "2007-04-09T21:18:35Z")

</div>

When my params for my observe\_field are empty or 0 I get the ‘template  
missing’ error. I’m trying to emulate the ‘user name is valid/not  
valid’ feature that many apps have when signing up. As long as the  
params is greater than zero everything is fine.

def already\_taken  
if params[:user].strip.length \> 0  
user = User.find\_by\_name(params[:user])  
if user  
render :update do |page|  
page[:already\_taken].replace\_html “Already taken!”  
page[:already\_taken].set\_style :color =\> ‘red’  
end  
elsif user == nil  
render :update do |page|  
page[:already\_taken].replace\_html “Available!”  
page[:already\_taken].set\_style :color =\> ‘green’  
end  
end  
end  
end

There must be an easier way to do this because it is such a common  
feature. Thanks for any help!

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [April 9, 2007, 9:30pm UTC](https://www.ruby-forum.com/t/how-to-get-around-observe-field-template-missing-error/91496/2 "2007-04-09T21:30:38Z")

</div>

On 09 Apr 2007, at 21:17, jko170 wrote:

> ```
> page[:already_taken].replace_html "Already taken!"
> 
> ```
> 
> There must be an easier way to do this because it is such a common  
> feature. Thanks for any help!

Well, you would be better off using javascript itself instead of the  
rails helper and check for the value being empty clientside and only  
query the server if a certain number of characters is entered, but if  
you want to stick with the rails helpers, you should add:

def already\_taken  
if params[:user].strip.length \> 0  
# do your thing  
else  
render :nothing =\> true  
end  
end

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [April 9, 2007, 10:38pm UTC](https://www.ruby-forum.com/t/how-to-get-around-observe-field-template-missing-error/91496/3 "2007-04-09T22:38:47Z")

</div>

Thanks a lot Peter!

I’m sure there’s a better way to do my entire project, but I guess  
this is fine for now (plenty of time to learn more and refactor after  
project is up).

---

<div class="post-metadata">

**Author:** ![jko170](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d07c76/32.png) [@jko170](https://www.ruby-forum.com/u/jko170)\
**Post date:** [April 11, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/how-to-get-around-observe-field-template-missing-error/91496/4 "2007-04-11T16:45:08Z")

</div>

I would recommend adding something like :condition =\> ‘value.length \>  
0’ to your observe form.

Also you can replace .strip.length \> 0 with .blank?
