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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:16:24+00:00 2026-06-01T16:16:24+00:00

I want to PUT to rails and avoid getting a 204 . I am

  • 0

I want to PUT to rails and avoid getting a 204. I am using this pattern:

class SomeController < ApplicationController
  respond_to :json

  def update
    # ...
    respond_with(some_object)
  end
end

However, when I do a put to update, I get a 204 back. I realize this is completely valid etc, but I explicitly want the content back. I can override it to some extent like this:

def update
  respond_with(some_object) do |format|
    format.json{render json: some_object}
  end
end

but this seems a bit too hands-on for rails. Is there any more idiomatic way of avoiding a 204 and requesting the full content to be sent back? This is Rails 3.2.

In summary: I want maximally idiomatic rails that avoids a 204.

  • 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-01T16:16:25+00:00Added an answer on June 1, 2026 at 4:16 pm

    I made a custom responder which always returns my JSON encoded resource even on PUT/POST.

    I put this file in lib/responders/json_responder.rb. Your /lib dir should be autoloaded.

    module Responders::JsonResponder
      protected
    
      # simply render the resource even on POST instead of redirecting for ajax
      def api_behavior(error)
        if post?
          display resource, :status => :created
        # render resource instead of 204 no content
        elsif put?
          display resource, :status => :ok
        else
          super
        end
      end
    end
    

    Now, explicitly modify the controller which requires this behavior, or place it in the application controller.

    class ApplicationController < ActionController::Base
    
      protect_from_forgery
    
      responders :json
    
    end
    

    You should now get JSON encoded resources back on PUT.

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

Sidebar

Related Questions

I'm starting in the Rails world and i want to know how to put
hey, hi i want put limit on object creation means a class can have
i want to put the id into the colorbox below this code nom works
I want to put together simple TCP server using Python and Twisted. The server
I am using this http://github.com/professionalnerd/simple-private-messages plugin in rails and I am on a user
I have this code in my every model. Class people def before_validation @attributes.each do
I am just very confused by this conflicting thing. I do want to put
I want to put spreedly in my new rails app.Because i am newbie can
I want to create recurring events using the Ice Cube gem in Rails -
I am using rails 2.3. I want to load parts of a page with

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.