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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:27:55+00:00 2026-05-13T21:27:55+00:00

I have an app running Rails 2.3.5 that has a JSON API for much

  • 0

I have an app running Rails 2.3.5 that has a JSON API for much of it.

A contractor came in and did some work on the app and used RJS in a few places. Some of those controller actions that are using RJS for the main web site also need to be part of the API.

The problem is that JSON API requests trigger the RJS responses, which is not what I want. I’d like the RJS responses to happen from a browser, but when it’s an API request (as distinguished by using the “application/json” Accept and Content-Type headers) then I’d like it to just send the API response.

From what I can tell, Rails triggers an RJS response for any MIME Type that involves javascript, i.e.

text/javascript
application/json

etc.

Is there a way to force RJS to only respond to text/javascript? Or is there a better way to solve this problem?

To make it more clear, I have code that looks like this:

def show
  @dashboard = @user.dashboard
  respond_to do |wants|
    wants.html
    wants.json { render :json => @dashboard }
  end
end

The trouble is, there is also a show.rjs template in the view folder for this controller. When someone hits the API, I want it to render the json results, as I have listed above, but instead, it renders the show.rjs template.

How can I make sure that API clients get the json results I want, and still let the RJS template render for people on the website?

  • 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-13T21:27:56+00:00Added an answer on May 13, 2026 at 9:27 pm

    You will need json defined in your mime_types.rb and then you should be able to do this:

    def show 
      @dashboard = @user.dashboard
      respond_to do |format|
        format.html
        format.json {render :json => @dashboard}
        format.js
      end
    end
    

    More to read here: http://ryanbigg.com/2009/04/how-rails-works-2-mime-types-respond_to/

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

Sidebar

Related Questions

I have a rails app (running on version 2.2.2) that has a model called
I have a Rails app that has been running fine for months. The other
I have a rails app running on port 3000. The page in question has
I have a rails app running on Heroku. I am using paperclip for some
I have got a Rails app running which displays data that is generated by
I have a Rails app that is running on port 8080 that I need
We have already built a rails app that has several users and an image
I have a Rails web app that is used to gather data from an
Introduction I have a app that has multiple tables, some with and some without
We have a web app running on Rails, using Devise and OmniAuth for user

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.