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?
The respond_with accepts some parameters, e.g. respond_with(@resource, methods: [:method]) These options should be used
Share
The easy and customizable way to do this is by creating a new response method that wraps responds_with.
For example:
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: