Forum: Ruby on Rails Clean incrementer across Ajax calls?

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.
E14633fe004ce897045cfbdea278c1a7?d=identicon&s=25 Nate Murray (jashmenn)
on 2006-05-07 07:14
Hey all, I want to have an ajax call that increments a number each time
it is
called. Basically I have want to render a partial that contains a call
to
append that same partial again at the end of the div. Perhaps it will
help
if I give the example code.

So in my view.rhtml i have:
=== view.rhtml ===
<div id="where_clause_div">
<%= link_to_remote 'Add',
                  { :update => 'where_clause_div',
                    :url    => { :action => :make_where_clause },
                    :position => :after}  %><br />
</div>

And in my controller I have:
=== controller.rb ===
...
  def make_where_clause
    @where_clause_id = 1 unless @where_clause_id; # This is always 1
    render :partial => 'where_clause',
           :locals => { :clause_id => @where_clause_id }
    @where_clause_id += 1
  end
...

And the partial is:
=== _where_clause.rhtml ===
<div class="where_clause" id="where_clause_<%= @where_clause_id %>">
The ID is: <%= @where_clause_id %>
<%= link_to_remote 'Add',
                  { :update => 'where_clause_div',
                    :url    => { :action => :make_where_clause },
                    :position => :after}  %>
</div>


My end goal is to get the "where_clause" div id in the partial to be
incremented on each ajax call. The only requirement is that I can't have
the
partial just increment its own variable because the 'add' link will
remain on
each of the divs.

Is there a clean way (short of a session variable) to do what I am
looking to do?
455ac2a64d06dc8461f4d258d7f7e980?d=identicon&s=25 Michael Trier (Guest)
on 2006-05-07 23:34
(Received via mailing list)
Funny, just did this yesterday, although doing something quite
different, and resorted to a session variable.  Tried lots of
different things, none of which were too elegant.  If you find a
better option, keep me in the loop.

Michael
This topic is locked and can not be replied to.