Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:00:19+00:00 2026-06-18T03:00:19+00:00

I have various values in a table that need to be updated after a

  • 0

I have various values in a table that need to be updated after a DOM element is updated using best_in_place. How can you trigger a javascript action like “create.js.erb” called “update.js.erb” after a best in place update?

For example, I have a table of item prices, and I need the table’s “total” field to update after a user updates an individual item quantity.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:00:20+00:00Added an answer on June 18, 2026 at 3:00 am

    I’ve seen many people asking this question, but haven’t found a satisfactory solution. I found the best approach is to create a javascript function that watches for a particular DOM element to update after an ajax:success, and then use jQuery to update a specified DOM element.

    In the controller of the item being updated, I package a JSON response that includes all of the information my javascript will need in order to update DOM elements.

    You’ll see I also render the new table row’s partial as an HTML string, and pass this string along with the JSON response.

    ___Item Controller_____
    
        respond_to do |format|
      if @item.update_attributes(params[:item])
    
        #json response variables to refresh table row after update
        id = [@item]  
        new_row = render_to_string('items/_item.html', :layout => false, :locals => { :item => @item })
        #----------json-variables-----------#
    
        format.json { render :json => { new_row: new_row, id: id, :status => 200 }}
        format.js   
      else
        format.json { render :json => @item.errors.full_messages, :status => :unprocessable_entity }
        format.js
      end
    end
    

    Then in a .js file that gets loaded with the page (like application.js), I include a function that watches for a table row with class “row_class” to be updated.

    $(document).ready(function(row_class, row_id_prefix){
    
    $("." + row_class).on("ajax:success",function(event, data, status, xhr){
        var parsed_data = jQuery.parseJSON(data); //parses string returned by controller into json object
    
        var id = parsed_data["id"];
        var new_row = parsed_data["new_row"]; //this is an html string that replaces the existing table row
    
        $('tr#' + row_id_prefix + id).replaceWith(new_row);
        $('tr#' + row_id_prefix + id).effect('highlight');
        $('.best_in_place').best_in_place(); //activates in-place-editing for newly added content.      
    }));        
    

    You can modify the jQuery to update any DOM element you need. Also, if you need the results of ruby methods called on objects (such as a humanized total, tax total, etc) you can define these as variables in the JSON object in the controller.

    Ultimately it’d be best if best_in_place would trigger (in this case) the items/update.js.erb script, but it doesn’t look like that’s on the roadmap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have various values and names stored in a db table, that my code
I am using Reflections to adjust various values in objects, and I have an
I have a SourceTable and a table variable @TQueries containing various T-SQL predicates that
I have a couple of values that I need to access from multiple programs.
I have a table that I'm trying to populate based on the values of
I have a database with a table that records data coming from various sources.
Problem I have various html tables that I need to parse/access from my customers
I have a requirement of retrieving various values such as Description, Office, etc. from
I have various objects in application,and each has isvalid method to test if values
Various online services have different values for maximum year of expiry, when it comes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.