我正在编写一个 API 来查找用户email_id。
将电子邮件作为参数发送时出现错误。
路线.rb:
Rails.application.routes.draw do
namespace :api do
resources :users, only: [:show, :index] , param: :email
end
end
Run Code Online (Sandbox Code Playgroud)
当我将电子邮件作为参数发送时,出现错误。URL 是http://localhost:3000/api/users/test@abc.com:
ActiveRecord::RecordNotFound in Api::UsersController#show
Couldn't find User with 'id'={:email=>"test@abc"}
Run Code Online (Sandbox Code Playgroud)
这是我的路线路径:
api_users_url GET /api/users(.:format) api/users#index
api_user_url GET /api/users/:email(.:format) api/users#show
Run Code Online (Sandbox Code Playgroud)