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 482457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:05:54+00:00 2026-05-13T01:05:54+00:00

I am putting some ajax into a rails project. I am trying to refresh

  • 0

I am putting some ajax into a rails project. I am trying to refresh a div with the contents of a partial.

page.replace_html("chemicals",  :partial => "chemicals", :object => @chemicals)

However, this returns a huge try/catch block, instead of re-rendering the partial correctly. any idea what’s going on?

the error is:

 try {Element.update("chemicals", "<table>\n  <tr>\n    <th> name</th>\n    <th>Cas</th>\n    <th>Amount</th>\n    <th>Units</th>\n    <th>Vendor</th>\n\t<th>Vendor email</th>\n\t<th>Vendor website</th>\n\t<th>Vendor phone</th>\n  </tr>\n\n\n\n  <tr>\n    <td>HCl</td>\n    <td><a href=\"http://chempedia.com/registry_numbers/\"></a></td>\n    <td>10</td>\n    <td>mL</td>\n    <td>Sigma-Aldrich</td>\n\t\n\t<td></td>\n\t<td>http://www.sigmaaldrich.com/sigma-aldrich/home.html</td>\n\t<td>800-325-3010</td>\n\t\n    <td><a href=\"/chemicals/28\">Show</a></td>\n    <td><a href=\"/chemicals/28/edit\">Edit</a></td>\n    <td><a href=\"/chemicals/28\" onclick=\"if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'dQYsh4Kz2kIX92HT0Ove43rO+qdz+/y5aozZIcdMWeg='); f.appendChild(s);f.submit(); };return false;\">Destroy</a></td>\n  </tr>\n\n</table>");
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.update(\"chemicals\", \"<table>\\n  <tr>\\n    <th> name</th>\\n    <th>Cas</th>\\n    <th>Amount</th>\\n    <th>Units</th>\\n    <th>Vendor</th>\\n\\t<th>Vendor email</th>\\n\\t<th>Vendor website</th>\\n\\t<th>Vendor phone</th>\\n  </tr>\\n\\n\\n\\n  <tr>\\n    <td>HCl</td>\\n    <td><a href=\\\"http://chempedia.com/registry_numbers/\\\"></a></td>\\n    <td>10</td>\\n    <td>mL</td>\\n    <td>Sigma-Aldrich</td>\\n\\t\\n\\t<td></td>\\n\\t<td>http://www.sigmaaldrich.com/sigma-aldrich/home.html</td>\\n\\t<td>800-325-3010</td>\\n\\t\\n    <td><a href=\\\"/chemicals/28\\\">Show</a></td>\\n    <td><a href=\\\"/chemicals/28/edit\\\">Edit</a></td>\\n    <td><a href=\\\"/chemicals/28\\\" onclick=\\\"if (confirm(\'Are you sure?\')) { var f = document.createElement(\'form\'); f.style.display = \'none\'; this.parentNode.appendChild(f); f.method = \'POST\'; f.action = this.href;var m = document.createElement(\'input\'); m.setAttribute(\'type\', \'hidden\'); m.setAttribute(\'name\', \'_method\'); m.setAttribute(\'value\', \'delete\'); f.appendChild(m);var s = document.createElement(\'input\'); s.setAttribute(\'type\', \'hidden\'); s.setAttribute(\'name\', \'authenticity_token\'); s.setAttribute(\'value\', \'dQYsh4Kz2kIX92HT0Ove43rO+qdz+/y5aozZIcdMWeg=\'); f.appendChild(s);f.submit(); };return false;\\\">Destroy</a></td>\\n  </tr>\\n\\n</table>\");'); throw e }

and when i say returns a try/catch block, that’s what’s being displayed on the browser.

edit:

part of the problem might be that instead of redirecting to localhost:3000/controller that I started in and pressed the delete button, i’m being redirect to localhost:3000/controller/id, where id is the id of the object i deleted. any idea what’s going on here?

also, it is correctly deleting the object. it just won’t go back to the right page. here is the line for the ‘delete’ link i’m clicking on, and the controller for ‘delete’.

<td><%= link_to 'Destroy', chemical, :confirm => 'Are you sure?', :method => :delete  %></td>

and

# DELETE /chemicals/1
  # DELETE /chemicals/1.xml
  def destroy
    @chemical = Chemical.find(params[:id])
    @chemical.destroy
    @chemicals = Chemical.all
    respond_to do |format|
      #format.html { redirect_to(chemicals_url) }
      #format.xml  { head :ok }
      format.js
    end
  end

(i made chemicals with script/generate scaffold chemicals)

  • 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-05-13T01:05:55+00:00Added an answer on May 13, 2026 at 1:05 am

    Although javascript is used to handle POST/PUT/DELETE requests, requests triggered by link_to still expect html and render the response as if it received html.

    Instead you should use link_to_remote which knows to execute whatever it receives assuming it got Javascript. This will do what you’re expecting it to do:

    <%= link_to_remote 'Destroy', :url => {:id => chemical.id, :action => :destroy}, 
          :confirm => 'Are you sure?', :method => :delete  %></td>
    

    P.S. The javascript returned to the browser will not be wrapped in that giant try block in production mode.

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

Sidebar

Related Questions

I am trying to implement paging across ajax calls. The page should not refresh
I have a rails app trying to incorporate some AJAX where clicking new opens
I'm putting some page content (which has been run through Tidy, but doesn't need
I am putting some heavy though into re-writing the data access layer in my
I was just putting some thought into different languages (as I'm reviewing for final
How do you do dynamic refresh of a single div tab using php/ajax and
I am trying to use z-index on some elements in a page. Basically, I
I am putting some email functionality into one of my asp.net projects: I need
I have been putting some data I have into my database. One of the
I am loading a Razor View via AJAX and putting the content into a

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.