Undefined instance method “respond_to” in Rails 5 API Controller

ActionController::API does not include the ActionController::MimeResponds module. If you want to use respond_to you need to include MimeResponds.

class ApplicationController < ActionController::API
  include ActionController::MimeResponds
end


module Api
  class MyController < ApplicationController
    def method1
      # ...
      respond_to do |format|
        format.xml { render(xml: "fdsfds") }
        format.json { render(json: "fdsfdsfd" ) }
      end
    end
  end
end

Source: ActionController::API docs

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)