Search code examples
ruby-on-railsruby-on-rails-3basic-authentication

basic auth with rails-api


I'm sure that I'm doing something wrong here, but this is what my application controller looks like:

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

  http_basic_authenticate_with :name => "joeyjojo", :password => "shabadoo"
end

I can't figure out why my http_basic_authenticate_with is throwing this error:

undefined method `http_basic_authenticate_with' for ApplicationController:Class

I'm sure it's something simple, but I don't see it. The MimeResponds is working just fine in other controllers.


Solution

  • You have to include ActionController::HttpAuthentication::Basic::ControllerMethods instead, to have the methods available. Here's the module in ActionController::Base