Forum: Ruby on Rails Updating query results in real time with AJAX

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
651af7b03ae5347b932fb231c94bbdf6?d=identicon&s=25 Bill (Guest)
on 2006-03-26 20:32
I have the following view template:

<%= form_remote_tag :update => "new_item",
                    :url => {:action => 'create'},
                    :before => %(Element.show('spinner')),
                    :success => %(Element.hide('spinner')) %>

<div id="new_item">

</div>

======================================================================
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 "<tr><td>" + @new_item[:id] + "</td><td>" +
@new_item[:category] + "</td></tr>"
    else
      render_action 'new'
    end
  end

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

Thanks,
Bill
651af7b03ae5347b932fb231c94bbdf6?d=identicon&s=25 Bill (Guest)
on 2006-03-26 20:36
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')) %>
>
> <div id="new_item">
>
> </div>
>
> ======================================================================
> 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 "<tr><td>" + @new_item[:id] + "</td><td>" +
> @new_item[:category] + "</td></tr>"
>     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 %>
D90ef6808433e63203e15a5c2dadb0bb?d=identicon&s=25 Ben Reubenstein (Guest)
on 2006-03-26 23:31
(Received via mailing list)
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 <bduenskie@gmail.com> wrote:
> > </div>
> > @new_item[:category] + "</td></tr>"
>
>
--
Ben Reubenstein
http://www.benr75.com
651af7b03ae5347b932fb231c94bbdf6?d=identicon&s=25 Bill (Guest)
on 2006-03-27 01:52
Ben Reubenstein 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 <bduenskie@gmail.com> wrote:
>> > </div>
>> > @new_item[:category] + "</td></tr>"
>>
>>
> --
> Ben Reubenstein
> 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.
277a81a86fd8af17759b2f38efb7e104?d=identicon&s=25 Ted Korolchuk (Guest)
on 2006-03-27 07:05
(Received via mailing list)
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 topic is locked and can not be replied to.