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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:36:57+00:00 2026-05-15T20:36:57+00:00

As you know, when you upgrade from Rails 2 to 3 you replace this:

  • 0

As you know, when you upgrade from Rails 2 to 3 you replace this:

link_to_remote "more", :url => {...}

with this:

link_to "more", {...}, :remote => true

But how do you handle the :update option in link_to_remote? In Railscast #205 Ryan Bates demonstrates link_to with :remote and a server response that includes JavaScript code to update a particular element in a page, but this practice seems wrong to me. I want my server’s response to be a simple HTML fragment which is easy to test and which can be used by different pages (clients) in different ways. I don’t think the server should have to know the ID of the target element on the requesting page as it ties the action to the page (a mini-client) and therefore makes it less general (it also feels uglier than a pure HTML response).

So, to be explicit, is there a way to do something like this:

link_to_remote "more", :url => {...}, :update => "products-list"

with Rails 3 and UJS? Or do I have to write JavaScript to capture the server’s HTML response and insert it into the right element on the page?

If the latter, please describe the best approach (can link_to‘s :remote option be used at all?).

  • 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-15T20:36:58+00:00Added an answer on May 15, 2026 at 8:36 pm

    I’m not 100% sure that this is the Rails-endorsed way to do it, but I’ve found a solution that works and seems pretty clean. Let’s say we have a page that lists the ten most popular products in our database. At the end is a link to load all remaining products via AJAX:

    <ul id="products-list">
      <li>...</li>
      <li>...</li>
      <li>...</li>
      ...
    </ul>
    <%= link_to "more...", "/products/all", :id => "load-more", :remote => true %>
    

    The server returns plain HTML (so that the link can be used on many different pages and is not bound to particular DOM IDs). We use the ajax:x events triggered by the Rails UJS drivers (here I’m using jQuery) to grab the server’s response and insert it into the right element on the page:

    <%= javascript_tag do %>
      $("#load-more").bind("ajax:complete", function(et, e){
        $("#products-list").html(e.responseText);
      });
    <% end %>
    

    If desired, we can also use the ajax:loading event to show a “spinner”:

    <%= javascript_tag do %>
      $("load-more").bind("ajax:loading", function(et, e){
        $(this).hide();
        $("#products-spinner").show();
      });
    <% end %>
    

    The Rails UJS drivers trigger four other events as well: ajax:success, ajax:failure, ajax:before, and ajax:after. See the driver included in your app (public/javascripts/rails.js) for more information.

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

Sidebar

Related Questions

I don't know exactly when, but assume with upgrade from Snow Leopard to Lion
I know I can update a single record like this - but then how
Know this might be rather basic, but I been trying to figure out how
I know that this sort of question has been asked here before, but still
i know this is a stupid question but i d'ont know how to do
I'm attempting to upgrade my Rails application to 3.2.0.rc2 but When I try to
I'd like to upgrade from Java 5 to Java 6. We all know about
Does anyone know the MSDN licensing rules around upgrade from visual studio 2008 to
What should someone know or do before they upgrade from XCode 3 to 4?
This is a weird one I know. I'm trying to tie together two Rails

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.