将Rails 5与Devise Token Auth gem(1.0.0)结合使用。 覆盖注册控制器:
# config/routes.rb
Rails.application.routes.draw do
devise_for :users, skip: :all
namespace :api do
namespace :v1 do
mount_devise_token_auth_for 'User', at: 'auth', controllers: { registrations: 'api/v1/auth/registrations' }
end
end
end
# app/controllers/api/v1/auth/registrations_controller.rb
class Api::V1::Auth::RegistrationsController < DeviseTokenAuth::RegistrationsController
def create
super do |resource|
resource.create_preference if resource.save
end
end
end
当我以开发和测试模式启动服务器时,一切正常。 当我推送到heroku或以生产模式启动服务器时,我会遇到以下问题:
$ rails s -e production
1: from /app/controllers/api/v1/auth/registrations_controller.rb:1:in `<main>'
/app/controllers/api/v1/auth/registrations_controller.rb:9:in `<class:RegistrationsController>': undefined local variable or method `' for Api::V1::Auth::RegistrationsController:Class (NameError)
我正在调查,但没有解决方案。 你能帮我吗?