# Updating query results in real time with AJAX

**URL:** <https://www.ruby-forum.com/t/updating-query-results-in-real-time-with-ajax/55985>\
**Category:** Rails\
**Created:** [March 26, 2006, 8:32pm UTC](https://www.ruby-forum.com/t/updating-query-results-in-real-time-with-ajax/55985 "2006-03-26T20:32:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [March 26, 2006, 8:32pm UTC](https://www.ruby-forum.com/t/updating-query-results-in-real-time-with-ajax/55985/1 "2006-03-26T20:32:57Z")

</div>

I have the following view template:

\<%= form\_remote\_tag :update =\> “new\_item”,  
:url =\> {:action =\> ‘create’},  
:before =\> %(Element.show(‘spinner’)),  
:success =\> %(Element.hide(‘spinner’)) %\>

======================================================================  
Here is the controller:

def create  
@category = Category.new(@params[:category])  
if @category.save  
@new\_item = Category.find\_by\_sql(“select max(category) as  
last\_category, id from categories”)  
render\_text “

” + @new\_item[:id] + “ ” +  
@new\_item[:category] + “ ”  
else  
render\_action ‘new’  
end  
end

I’m a complete newbie, any help would be appreciated.

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [March 26, 2006, 8:36pm UTC](https://www.ruby-forum.com/t/updating-query-results-in-real-time-with-ajax/55985/2 "2006-03-26T20:36:50Z")

</div>

Bill wrote:

> I have the following view template:
> 
> \<%= form\_remote\_tag :update =\> “new\_item”,  
> :url =\> {:action =\> ‘create’},  
> :before =\> %(Element.show(‘spinner’)),  
> :success =\> %(Element.hide(‘spinner’)) %\>
> 
> ======================================================================  
> Here is the controller:
> 
> def create  
> @category = Category.new(@params[:category])  
> if @category.save  
> @new\_item = Category.find\_by\_sql(“select max(category) as  
> last\_category, id from categories”)  
> render\_text “
> 
> ” + @new\_item[:id] + “ ” +  
> @new\_item[:category] + “ ”  
> else  
> render\_action ‘new’  
> end  
> end
> 
> I’m a complete newbie, any help would be appreciated.
> 
> Thanks,  
> Bill

I forgot to mention, my view controller also has the following input  
field:  
\<%= text\_field “category”, “category”, “size”=\>20, “maxlength”=\>20 %\>

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [March 26, 2006, 11:31pm UTC](https://www.ruby-forum.com/t/updating-query-results-in-real-time-with-ajax/55985/3 "2006-03-26T23:31:37Z")

</div>

Hi Bill ~

What seems to be the issue? Just posting source makes it tough for us  
to offer advice.

~ Thx,

Ben

On 3/26/06, Bill [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > @new\_item[:category] + ""

–  
Ben R.  
[http://www.benr75.com](http://www.benr75.com)

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [March 27, 2006, 1:52am UTC](https://www.ruby-forum.com/t/updating-query-results-in-real-time-with-ajax/55985/4 "2006-03-27T01:52:36Z")

</div>

Ben R. wrote:

> Hi Bill ~
> 
> What seems to be the issue? Just posting source makes it tough for us  
> to offer advice.
> 
> ~ Thx,
> 
> Ben
> 
> On 3/26/06, Bill [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > @new\_item[:category] + ""
> 
> –  
> Ben R.  
> [http://www.benr75.com](http://www.benr75.com)

When you submit the form to enter the new category i’d like to display  
the new category without refreshing the page, ala AJAX.

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [March 27, 2006, 7:05am UTC](https://www.ruby-forum.com/t/updating-query-results-in-real-time-with-ajax/55985/5 "2006-03-27T07:05:30Z")

</div>

Have you tried doing this? Is there some reason you can’t get it to  
work?

Not to be rude, but I think you should try to do this yourself first,  
and if  
you have trouble with it, then report it to the list.

If you can’t figure out where to start, read.
