[rails] Clean incrementer across Ajax calls?

Discussion in 'Ruby' started by Nate Murray, May 7, 2006.

  1. Nate Murray

    Nate Murray Guest

    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?
    Nate Murray, May 7, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. amit kumar
    Replies:
    5
    Views:
    6,133
    velthuijsen
    May 18, 2004
  2. Replies:
    8
    Views:
    510
  3. Dave
    Replies:
    2
    Views:
    530
    Chris Rebert
    May 15, 2010
  4. Robert Millman

    Serialization / Deserialization across WebService Calls

    Robert Millman, Feb 5, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    99
  5. John Granade

    Keep object across web service calls?

    John Granade, Oct 9, 2007, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    136
    John Granade
    Oct 9, 2007
Loading...

Share This Page