繁体   English   中英

无法在轨道上使用反应 ruby 和 devise gem 注册用户

[英]Unable to sign up a user with react ruby on rails and devise gem

我正在使用带有 React 的 Rails 6 和带有 devise gem 的 webpacker。 我发出一个帖子请求,它到达了正确的路线,给了我一个状态 200 OK。 没有错误信息。 但是当我使用rails console检查用户时,它显示没有新用户。

这些是我的代码文件供参考。 任何帮助将不胜感激。

  const handleSubmit = (event) => {
    
    axios.post('/api/v1/users', inputs)
    .then( res => {
      console.log(res);
    }).catch( res => {
      console.log(res)
    })
  }

铁路路线

                 new_api_v1_user_session GET    /api/v1/users/sign_in(.:format)                                                                   api/v1/users/sessions#new
                     api_v1_user_session POST   /api/v1/users/sign_in(.:format)                                                                   api/v1/users/sessions#create
             destroy_api_v1_user_session DELETE /api/v1/users/sign_out(.:format)                                                                  api/v1/users/sessions#destroy
                new_api_v1_user_password GET    /api/v1/users/password/new(.:format)                                                              api/v1/users/passwords#new
               edit_api_v1_user_password GET    /api/v1/users/password/edit(.:format)                                                             api/v1/users/passwords#edit
                    api_v1_user_password PATCH  /api/v1/users/password(.:format)                                                                  api/v1/users/passwords#update
                                         PUT    /api/v1/users/password(.:format)                                                                  api/v1/users/passwords#update
                                         POST   /api/v1/users/password(.:format)                                                                  api/v1/users/passwords#create
         cancel_api_v1_user_registration GET    /api/v1/users/cancel(.:format)                                                                    api/v1/users/registrations#cancel
            new_api_v1_user_registration GET    /api/v1/users/sign_up(.:format)                                                                   api/v1/users/registrations#new
           edit_api_v1_user_registration GET    /api/v1/users/edit(.:format)                                                                      api/v1/users/registrations#edit
                api_v1_user_registration PATCH  /api/v1/users(.:format)                                                                           api/v1/users/registrations#update
                                         PUT    /api/v1/users(.:format)                                                                           api/v1/users/registrations#update
                                         DELETE /api/v1/users(.:format)                                                                           api/v1/users/registrations#destroy
                                         POST   /api/v1/users(.:format)                                                                           api/v1/users/registrations#create

module Api 
  module V1 



# frozen_string_literal: true

class Users::RegistrationsController < Devise::RegistrationsController
  before_action :configure_sign_up_params, only: [:create]
  # before_action :configure_account_update_params, only: [:update]
  skip_forgery_protection
  # GET /resource/sign_up
  def new
    super
  end

  # POST /resource
  def create
    super
    debugger
  end

  # GET /resource/edit
  # def edit
  #   super
  # end

  # PUT /resource
  # def update
  #   super
  # end

  # DELETE /resource
  # def destroy
  #   super
  # end

  # GET /resource/cancel
  # Forces the session data which is usually expired after sign
  # in to be expired now. This is useful if the user wants to
  # cancel oauth signing in/up in the middle of the process,
  # removing all OAuth session data.
  # def cancel
  #   super
  # end

  # protected

  # If you have extra params to permit, append them to the sanitizer.
  def configure_sign_up_params
    devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
  end

  # If you have extra params to permit, append them to the sanitizer.
  # def configure_account_update_params
  #   devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
  # end

  # The path used after sign up.
  def after_sign_up_path_for(resource)
    # super(resource)
    
  end

  # The path used after sign up for inactive accounts.
  # def after_inactive_sign_up_path_for(resource)
  #   super(resource)
  # end
end
end 
end

似乎设计的注册 controller 确实可以保存,这意味着在某些验证的情况下它可能不会引发错误。 可能只是您向其传递了错误的参数,因此无法创建用户。 要调试它,您可以尝试检查进入设计 controller 的内容以及您可能缺少的内容。 您可以通过在本地执行一些 put 或登录 devise 库代码来实现这一点(当然只是暂时的)。

编辑:实际上它可能更糟,因为它使用 flash 消息呈现视图,因此响应将始终为 200 OK,除非您在扩展它的 controller 中的代码中弄乱了一些东西。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM