URI::InvalidComponentError:坏组件(期望主机组件):localhost:3000。

6

我不确定出了什么问题,但在控制台运行NewsletterMailer.weekly("username-here@gmail.com").deliver时,我收到错误消息URI::InvalidComponentError: bad component(expected host component): localhost:3000

我检查过我的设置,一切似乎都正常。以下是完整的错误输出:

    from /Users/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/uri/generic.rb:605:in `check_host'
    from /Users/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/uri/generic.rb:646:in `host='
    from /Users/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/uri/generic.rb:195:in `initialize'
    from /Users/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/uri/generic.rb:141:in `new'
    from /Users/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/uri/generic.rb:141:in `build'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/roadie-2.4.3/lib/roadie/inliner.rb:206:in `absolute_url_base'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/roadie-2.4.3/lib/roadie/inliner.rb:192:in `ensure_absolute_url'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/roadie-2.4.3/lib/roadie/inliner.rb:180:in `block in make_image_urls_absolute'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/nokogiri-1.6.1/lib/nokogiri/xml/node_set.rb:237:in `block in each'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/nokogiri-1.6.1/lib/nokogiri/xml/node_set.rb:236:in `upto'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/nokogiri-1.6.1/lib/nokogiri/xml/node_set.rb:236:in `each'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/roadie-2.4.3/lib/roadie/inliner.rb:179:in `make_image_urls_absolute'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/roadie-2.4.3/lib/roadie/inliner.rb:57:in `block in execute'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/roadie-2.4.3/lib/roadie/inliner.rb:80:in `block in adjust_html'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/roadie-2.4.3/lib/roadie/inliner.rb:79:in `tap'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/roadie-2.4.3/lib/roadie/inliner.rb:79:in `adjust_html'
... 10 levels...
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.0.rc1/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0.rc1/lib/active_support/callbacks.rb:392:in `_run__4195001508967449441__process_action__callbacks'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0.rc1/lib/active_support/callbacks.rb:80:in `run_callbacks'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.0.rc1/lib/abstract_controller/callbacks.rb:17:in `process_action'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.0.rc1/lib/abstract_controller/base.rb:136:in `process'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.0.rc1/lib/abstract_controller/rendering.rb:44:in `process'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/actionmailer-4.0.0.rc1/lib/action_mailer/base.rb:503:in `process'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/actionmailer-4.0.0.rc1/lib/action_mailer/base.rb:497:in `initialize'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/actionmailer-4.0.0.rc1/lib/action_mailer/base.rb:480:in `new'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/actionmailer-4.0.0.rc1/lib/action_mailer/base.rb:480:in `method_missing'
    from (irb):1
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.0.rc1/lib/rails/commands/console.rb:90:in `start'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.0.rc1/lib/rails/commands/console.rb:9:in `start'
    from /Users/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.0.rc1/lib/rails/commands.rb:66:in `<top (required)>'

Development.rb:

 config.cache_classes = false

  config.eager_load = false

  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  config.action_mailer.raise_delivery_errors = false

  config.active_support.deprecation = :log

  config.assets.debug = true

  config.eager_load = false

  # Change mail delvery to either :smtp, :sendmail, :file, :test
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            'username-here@gmail.com',
    password:             'password-here',
    authentication:       'plain',
    enable_starttls_auto: false  }

  config.action_mailer.default_url_options = { :host => "localhost:3000" }

end
4个回答

5

从指定为默认主机的URL中删除端口号。 :host键的值应该只是主机名,而不是主机名和端口号。


你在进行配置更改后重新启动了服务器吗? - Zajn
是的,我重新启动了服务器。 - xps15z
我正在使用Letter Opener,但在邮件中仍然收到file://users/121/edit并且缺少主机,请问你能帮忙吗? - Vishal

2
如果 Zajn 的答案没有起作用,请搜索 localhost:3000。你可能已经将其设置在其他地方了。当你找到它时,删除这一行,然后它应该可以正常工作。

2
您可能在您的配置文件(也许是development.rb)中有这样一行代码:config.roadie.url_options = { host: "localhost:3000" }。 然而,road.url_options需要将端口单独指定为一个键值对。
请尝试使用config.roadie.url_options = { host: "localhost", port: 3000 }代替原来的代码。

0

我遇到了同样的问题,尝试使用这个命令来启动服务器

bundle exec rails server -b 127.0.0.1 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接