我对路由感到困惑,我正在处理json数据admin / admins_controller.rb
获取路由错误No route matches [POST] "/admin/adminsignup"*
admin / admins_controller.rb
class Admin::AdminsController < ApplicationController
skip_before_action :verify_authenticity_token
def adminlogin
user = User.where(email: params[:email]).first
if user&.valid_password?(params[:password])
render json: user.as_json(only: :email,:first_name,:last_name,:phone,:authentication_token]), status: :created
else
head(:unauthorized)
end
end
def adminsignup
user = User.new(user_params)
if user.save
render json: {status: 'success', data:user}, status: :ok
else
render json: {status: 'error', message:'There was some error in registering the user.', data:user.errors}, status: :unprocessable_entity
end
end
def logindestroy
current_user&.authentication_token = nil
if current_user.save
head(:ok)
else
head(:unauthorized)
end
end
private
def user_params
params.permit(:first_name, :last_name, :email, :password, :phone)
end
end
routes.rb
namespace :admin do
post 'admins', to: 'admins#adminlogin'
post 'admins', to: 'admins#adminsignup'
destroy 'admins', to: 'admins#logindestroy'
end
user.rb
class User < ApplicationRecord
acts_as_token_authenticatable
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
是更好的方法吗?请帮忙。