# Ajax observer sending weird param

**URL:** <https://www.ruby-forum.com/t/ajax-observer-sending-weird-param/179759>\
**Category:** Rails\
**Created:** [December 3, 2009, 10:35am UTC](https://www.ruby-forum.com/t/ajax-observer-sending-weird-param/179759 "2009-12-03T10:35:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [December 3, 2009, 10:35am UTC](https://www.ruby-forum.com/t/ajax-observer-sending-weird-param/179759/1 "2009-12-03T10:35:02Z")

</div>

Hey guys,  
I’m trying to use Ruby on Rails w/ Ajax… I’m getting a funky little  
problem. So I’ve got an observer on a text field called username and I’m  
trying to just check to see if the username is already in the DB or not,  
then display the appropriate message. Here’s the form part in my RHTML  
file:

\<%= text\_field\_tag :username %\>  
\<%= observe\_field(:username, :frequency =\> 0.25,:update =\>  
:div\_username,:url =\> { :action =\> :checkUsername }) %\>

…my controller

def checkUsername  
if(User.checkUsername(params[:username])==1)  
render :text =\> “#{params[:username]} is not available”  
else  
render :text =\> “available”  
end  
end

The problem is that params[:username] is never set!! When I look at  
whats going on the backend, it shows me that username I typed in is the  
param name! For example, if I typed in “jsmith” into the username field,  
it sends param[:jsmith]=\>nil to the controller. I’m really confused, if  
anyone could help me figure this out, I’d really appreciate it!

Thanks,

- Jeff

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [December 3, 2009, 11:43am UTC](https://www.ruby-forum.com/t/ajax-observer-sending-weird-param/179759/2 "2009-12-03T11:43:44Z")

</div>

Hi Jeff M.

There is with option to observefield There you have to pass username  
like

\<%= observe\_field(:username, :frequency =\> 0.25,:update =\>  
:div\_username,:url =\> { :action =\> :checkUsername }, :with =\>  
“‘username=’ + $(‘username’).value”) %\>

```
 Now you can access params[:username] from controller as you do

```

Sijo

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [December 3, 2009, 9:48pm UTC](https://www.ruby-forum.com/t/ajax-observer-sending-weird-param/179759/3 "2009-12-03T21:48:35Z")

</div>

Thanks for the quick and very helpful reply, Sijo! Got it working 🙂
