我不能为我的生活弄清楚为什么这不起作用。每当我尝试注册用户时,我都会收到此错误。它说我可能没有在devise_scope :user; ...; end;
我的注册管理员:
class Api::V1::RegistrationsController < Devise::RegistrationsController
skip_before_filter :verify_authenticity_token,
if: Proc.new { |c| c.request.format == 'application/json' }
before_action :configure_permitted_parameters
respond_to :json
def create
build_resource(sign_up_params)
if resource.save
login(resource)
render status: 200,
json: resource,
serializer: CurrentUserSerializer,
root: "user",
meta: { success: true,
info: "Registered" }
else
render status: :unprocessable_entity,
json: { errors: resource.errors.full_messages }
end
end
private
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(:name, :email, :password, :password_confirmation)
end
end
end
我的路线控制器很重要:
namespace :api do
namespace :v1 do
devise_scope :user do
post 'registrations' => 'registrations#create', as: 'register'
post 'sessions' => 'sessions#create', as: 'login'
delete 'sessions' => 'sessions#destroy', as: 'logout'
end
end
end
我不确定为什么会收到此错误。
答案 0 :(得分:0)
在使用devise_for, skip => :all
声明自定义路由之前,您只需要调用devise_scope
添加资源映射,如下所示:
devise_for :users, skip: :all
devise_scope :user do
# custom routes here
end
供参考,此处讨论:https://github.com/plataformatec/devise/issues/2840#issuecomment-67783871