You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ActiveAdmin Devise管理员重置密码功能ArgumentError问题求助

ActiveAdmin重置密码功能ArgumentError排查建议

排查步骤:

  • 检查ActiveAdmin专属邮件配置:ActiveAdmin可能不会直接继承全局action_mailer的default_url_options,需在config/initializers/active_admin.rb中显式配置:
    config.mailer_defaults = {
      default_url_options: { host: ENV['APP_HOST'] } # 替换为你的实际host值或环境变量
    }
    
  • 验证环境变量加载顺序:如果使用dotenv,确保dotenv-rails在Gemfile中位于rails之前,或在config/application.rb提前加载:
    require 'dotenv/load' if %w[development test].include?(Rails.env)
    
  • 检查邮件生成上下文:若自定义了重置邮件模板/控制器,不要手动构造链接,使用ActiveAdmin提供的edit_admin_password_path,且确保调用时未覆盖host参数。
  • 控制台验证配置有效性:启动rails控制台,执行以下命令确认配置已加载:
    # 检查路由默认host
    Rails.application.routes.default_url_options[:host]
    # 检查邮件默认host
    ActionMailer::Base.default_url_options[:host]
    
    若返回nil,说明对应环境配置文件(如config/environments/production.rb)中的设置有误,注意拼写、大小写及端口(如development环境需写localhost:3000而非仅localhost)。
  • 排查多环境配置冲突:确认各环境(development/test/production)的config.action_mailer.default_url_options均正确设置,production环境需确保环境变量已正确部署。

报错信息:

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

报错代码:

unless host
  raise ArgumentError, "Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true"
end

build_host_url(host, port, protocol, options, path_for(options))

内容的提问来源于stack exchange,提问作者nothing like anime

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 08:01:02