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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:53:26+00:00 2026-05-14T03:53:26+00:00

I’m trying to make an API for my rails application using JSON responses to

  • 0

I’m trying to make an API for my rails application using JSON responses to RESTful resource controllers. This is a new experience for me, so I’m looking for some guidance and pointers. To start things off:

  1. In a rails application, what is the “proper” way to respond with JSON to REST-ful controller methods? (create, update, destroy)
  2. Is there an idiomatic way to indicate success/failure through a JSON response?

Additional information:

  • I’m currently working with rails 3.0.beta2
  • I would like to avoid using a plugin or gem to do the grunt work, my goal is to gain a better understanding of how to make a rails 3 API.
  • Links to places I could find more information on the topic would also be appreciated, some quick searching on google didn’t do me much good.
  • 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-14T03:53:26+00:00Added an answer on May 14, 2026 at 3:53 am
    #config/routes.rb
    MyApplicationsName::Application.routes.draw do
      resources :articles
    end
    
    #app/controllers/articles_controller.rb
    class ArticlesController < ActionController::Base
    
      # so that respond_with knows which formats are
      # allowed in each of the individual actions
      respond_to :json
    
      def index
        @articles = Article.all
        respond_with @articles
      end
    
      def show
        @article = Article.find(params[:id])
        respond_with @article
      end
    
      ...
    
      def update
        @article = Article.find(params[:id])
        @article.update_attributes(params[:article])
    
        # respond_with will automatically check @article.valid?
        # and respond appropriately ... @article.valid? will
        # be set based on whether @article.update_attributes
        # succeeded past all the validations
        # if @article.valid? then respond_with will redirect to
        # to the show page; if !@article.valid? then respond_with
        # will show the :edit view, including @article.errors
        respond_with @article
      end
    
      ...
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.