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

  • Home
  • SEARCH
  • 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 8622521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:04:36+00:00 2026-06-12T07:04:36+00:00

The respond_with accepts some parameters, e.g. respond_with(@resource, methods: [:method]) These options should be used

  • 0

The respond_with accepts some parameters, e.g. respond_with(@resource, methods: [:method])
These options should be used in every action. So instead of putting it into every method by hand, is there a possibility to set some default options for just this controller?

  • 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-12T07:04:37+00:00Added an answer on June 12, 2026 at 7:04 am

    The easy and customizable way to do this is by creating a new response method that wraps responds_with.

    For example:

    class ResourcesController < ApplicationController
    
      def index
        @resources = Resource.all
    
        custom_respond_with @resources
      end
    
    private
    
      def custom_respond_with(data, options={})
        options.reverse_merge!({
          # Put your default options here
          :methods => [ :method ],
          :callback => params[:callback]
        })
        respond_with data, options
      end
    end
    

    You could, of course, also overwrite the respond_with completely, however, I find it to be much clearer in the code if you change the name of the method. It also will allow you to use a custom_respond_with in most actions but the standard respond_with in one or two if necessary.

    Taking this one step further, if you move the custom_respond_with method to the ApplicationController, you can use it in all of your controllers as necessary.

    If you want to specify different default options on a per controller basis, you can do so easily:

    class ResourcesController < ApplicationController
    
      def index
        custom_respond_with Resource.all
      end
    
    private
    
      def custom_respond_options
        { :methods => [ :method ] }
      end
    
    end
    
    class ApplicationController < ActionController::Base
    
    protected
    
      def default_custom_respond_options
        {}
      end      
    
      def custom_respond_with(data, options={})
        options.reverse_merge! default_custom_respond_options
        respond_with data, options
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python webapp which accepts some data via POST. The method which
I have a page ( page 1 ) that accepts post requests, does some
I'm trying to understand why respond_with/to is rendering the wrong view... controller respond_to :html,
I have a ViewPager with 4 views. View #3 needs to respond to some
Morning Everyone, I've been attempting to write an application that does some GETs from
I was doing some reading and have even gotten a master SPI working on
after several months having the site disappear from search results in every major search
I have a REST API which accepts XML in HTTP Posts. When I send
I'm writing some code that makes an AJAX request to our web server. Our
This is a follow up post to some problems I've had using Java built

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.