I've got a rails application which uses Devise for authentication and works fine in the browser. I want to configure it so that it will interact with an Android application I'm building. I'm trying to override the standard JSON response so that it returns the authentication token which I need to login.
This problem seems to be answered in this question and I'm trying to adapt it. Using Devise tokens to log in, is this built in?
I have specified the following config/initializers/devise.rb:
config.token_authentication_key = :auth_token
I've changed my routes file so that it looks like this: devise_for :managers, :controllers => { :sessions => "Managers/sessions" }
And then I've created a file sessions_controller.rb with the following:
class Managers::SessionsController < Devise::SessionsController
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_to do |format|
format.html do
respond_with resource, :location => redirect_location(resource_name, resource)
end
format.json do
render :json => { :response => 'ok', :auth_token => current_user.authentication_token }.to_json, :status => :ok
end
end
end
end
However when I try to run the application I get the following error:
Routing Error uninitialized constant Managers
What's causing this error? Any suggestions for how to correct this so that I can still log in via JSON?
Thanks in advance for your help!
Antony