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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:38:12+00:00 2026-05-27T01:38:12+00:00

I have a index view in a Rails 3 project where several line items

  • 0

I have a index view in a Rails 3 project where several line items are listed along with a corresponding count. For example:

Name     Count
--------------
Item A     10
Item B    278
Item c     64

The list is dynamic in length, however I know each item’s id, and I have a partial which displays a passed-in count.

How would I change this setup to display the count via AJAX (jQuery)?

For example, I would want the intial spot where the count is to be a spinner. And the spinner would be replaced with the actual count after being triggered somehow. But I need this for each and every item in the list.

For your answer to be useful for me please provide detailed steps and sample code. Thank you!

  • 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-27T01:38:12+00:00Added an answer on May 27, 2026 at 1:38 am

    I eventually came up with a solution for this.

    In the controller (samples_controller.rb):

    # GET /samples/1/count
    def count
      sample = Sample.find(params[:id])
      count = sample.data.count
      count_title = "#{number_with_delimiter(count)} samples"
    
      respond_to do |format|
        format.js {
          if count > 0
            render :partial => 'partials/count', :locals => {:count => count, :count_title => count_title}
          else
            render :nothing => true
          end
        }
      end
    end
    

    In the view (samples/index.html.erb):

    <table>
    <% @samples.each do |sample| %>
    <tr>
      <td class="sample_count">
        <div data-id='<%= sample.id %>'>
          <img src="/images/icons/spinner.gif"/>
        </div>
      </td>
    <tr>
    <% end %>
    </table>
    

    The javascript in the view:

    <script type='text/javascript'>
        $(document).ready(function() {
            $('.sample_count div').each(function() {
                $(this).load('/samples/' + $(this).attr('data-id') + '/count');
            });
        });
    </script>
    

    In the config/routes.rb:

    controller :samples do
      get "samples" => :index
      delete "samples/:id" => :destroy
      get "samples/:id/count" => :count
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my rails view(index.html.erb), i have following structure <div> <%= render :partial => create
I have a view in a Django 1.4 project: def index(request): print reverse('menus_index') latest_menu_list
This is a Rails 3 project using jQuery 1.4.4. I have an index action
I have an index view that I want to update automatically as the user
I have the following code in my index view. latest_entry_list = Entry.objects.filter(is_published=True).order_by('-date_published')[:10] for entry
If I have a HomeController displaying its Index view, how would I proceed in
Ok Here is the exact scenario: I have a view named Index I have
I have a view and template called index.html. I have a image which is
I have the following view: @model MyModel1 @{ ViewBag.Title = Index; Layout = ~/Views/Shared/_Layout.cshtml;
I have a listbox (detailed view). How do I get the index of the

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.