我正在使用Devise对我的rails app和api进行身份验证。
当我从我的api向/api/v1/users/password
发送重置密码链接时,它会发送电子邮件,但电子邮件中的链接会转到http://localhost:3000/api/v1/users/password/edit?reset_password_token=A2opghht5cy5ATiezGe1
如何进入http://localhost:3000/users/password/edit?reset_password_token=A2opghht5cy5ATiezGe1
这是我的 routes.rb
Rails.application.routes.draw do
namespace :api, defaults: { format: "json" } do
namespace :v1 do
devise_for :users
resources :users
end
end
devise_for :users
resources :users
end
以下是app/controllers/api/v1/passwords_controller.rb
module Api
module V1
class PasswordsController < Devise::PasswordsController
skip_before_filter :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' }
respond_to :json
def create
@user = User.send_reset_password_instructions(params[:user])
if successfully_sent?(@user)
render :status => 200, :json => {:success => true}
else
render :status => 422, :json => { :errors => @user.errors.full_messages }
end
end
end
end
end