Updating query results in real time with AJAX

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

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 %>

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 [email protected] wrote:

@new_item[:category] + ""


Ben R.
http://www.benr75.com

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 [email protected] wrote:

@new_item[:category] + ""


Ben R.
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.

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs