← Back to Upcase

Adding modules to an API-only Rails app

(Alex P) #1

Hi all! Quick question. In this section of the guide, there’s a short list of ActionController modules that can be optionally added back in to API-only apps. But when I try to include the module for HTTP Basic Authentication, Rails is throwing a 404 error.


class ApplicationController < ActionController::API
  include ActionController::HttpAuthentication::Basic

Test controller:

class TestController < ApplicationController
  http_basic_authenticate_with name: "asdf", password: "password"

If I switch

ApplicationController < ActionController::API


ApplicationController < ActionController::Base

then the http_basic_authenticate_with method works properly. But when it inherits from ActionController::API, I get the error:

#<ActionController::RoutingError: undefined method 'http_basic_authenticate_with' ...

Do I need to include that module in a different way?