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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:52:38+00:00 2026-06-14T07:52:38+00:00

I know this question has been asked in part a few other times on

  • 0

I know this question has been asked in part a few other times on SO but I was curious about doing it a different way. In my Ruby on Rails app I have an action called list on my UsersController.rb controller. I want this list to respond to 3 different things

  1. The page itself. Rending the whole page of users I specify
  2. A JSON list of users for the page I specify
  3. A partial view of just the rows for the page I’m specifying formatted as HTML.

Imagine a full page (header, footer, everything) with a table that has page 1 of users. When I click page 2 I want to kick off an ajax request back to the same controller action to give me just the html rows for page 2. I also want to persist my JSON API still allowing my controller to return JSON lists when asked. I imagine it looking someting like this.

class UsersController < ApplicationController
    def list
        respond_to do |format|
            format.html # RETURNS MY VIEW
            format.json # RETURNS MY JSON LIST
            format.partial_html # RETURNS MY PARTIAL HTML
        end
    end
end

Is there anyway to accomplish this in RoR? Or am I doomed into having to create another action in my controller just to return technically the same data?

Could I make this happen by specifying my own MIME type? Should I snake in the partial as an XML return type?

  • 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-14T07:52:39+00:00Added an answer on June 14, 2026 at 7:52 am
    1. Use format.js on the third line.
    2. Put the partial html on a partial, call it app/views/users/_html_rows.html.erb.
    3. render that partial both on the full html and on the js version.

    You will have app/views/users/list.html.erb with the full html content, which will be something like this:

    <html>
    <body>
    .....
    <table id="my_table"><%= render 'users/html_rows', users: @users %></table>
    </body>
    </html>
    

    You will have app/views/users/_html_rows.html.erb with:

    <tbody>
      <% users.each do |user| %>
        <tr>
          <td>user.name</td>
        </tr>
    </tbody>
    

    Then you will have app/views/users/list.js.erb with:

    $("#my_table tbody").html("<%= render 'users/html_rows', users: @users %>");
    

    This probably will solve your problem.

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

Sidebar

Related Questions

I know this question has been asked here a few times before. But i
So I know this question has been asked 20 other times and 20 different
I know this question has been asked few times over SO but none of
I know this question has been asked a zillion times, but I still feel
I know this question has been asked before numorous times but they seem to
I know this question has been asked countless of times. But none of them
Yes, I know this question has been asked a lot of times, but I
I know this question has been asked quite a few times, however, I have
I know this question has been asked many times, but my problem is a
I know this question has been asked and answered many times. But almost all

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.